在 XAML 控件的资源(如下)中声明 DataTemplateSelector 时,如何将它提供/绑定到不是 ItemsSource 成员的运行时值?例如,它可能需要服务、数据源、配置参数等
示例:参考。“这如何从数据上下文或支持代码中提供???”
<UserControl.Resources>
<DataTemplate x:Key="StringDataTemplate">
<TextBox Grid.Column="2" Text="{Binding Value}" />
</DataTemplate>
<DataTemplate x:Key="DateDataTemplate">
<DatePicker Grid.Column="2" SelectedDate="{Binding Value}" />
</DataTemplate>
<local:MyDataTemplateSelector x:Key="templateSelector"
SomeRuntimeValue="How Can This Be Supplied From The Data Context or Backing Code???"
StringDataTemplate="{StaticResource StringDataTemplate}"
BooleanDataTemplate="{StaticResource BooleanDataTemplate}"/>
</UserControl.Resources>
<StackPanel>
<ListBox ItemsSource="{Binding SomeDataCollection}"
Grid.IsSharedSizeScope="True"
HorizontalContentAlignment="Stretch"
ItemTemplateSelector="{StaticResource templateSelector}"/>
</StackPanel>
提前致谢 :)