这是我的 XAML
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basic="clr-namespace:Emule.GUI.Design.Templates"
xmlns:Search="clr-namespace:Emule.GUI.Features.Search"
xmlns:Finder="clr-namespace:Emule.GUI.Util.Finder"mc:Ignorable="d"
x:Class="Emule.GUI.Features.Search.View" Title="View" Height="454" Width="696">
<!-- Default DataTemplate -->
<DataTemplate x:Key="DefaultDataTemplate">
<TextBox Grid.Row="2" Grid.Column="2" x:Name="joe"
Visibility="{Binding OperatorValueVisibility, Mode=OneWay}"
Text="{Binding OperatorValue, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
<!-- DataTemplate for string list -->
<DataTemplate x:Key="ListStringDataTemplate">
<basic:ListValuesSearch MinHeight ="740" x:Name="ListValues" />
</DataTemplate>
<!-- DataTemplate Selector -->
<Search:PropertyDataTemplateSelector x:Key="templateSelector"
DefaultDataTemplate="{StaticResource DefaultDataTemplate}"
BooleanDataTemplate="{StaticResource BooleanDataTemplate}"
EnumDataTemplate="{StaticResource EnumDataTemplate}"/>
<StackPanel Grid.Row="2" Grid.Column="2" HorizontalAlignment="Left" >
<ContentControl ContentTemplateSelector="{StaticResource templateSelector}"
Content="{Binding Path=PoDFinder.CodicePod}" />
</StackPanel>
</Window>
这是我的控制(wpftoolkit 数据网格)
<UserControl x:Class="Emule.GUI.Design.Templates.ListValuesSearch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:Finder="clr-namespace:Emule.GUI.Util.Finder">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="DataGrid.Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel>
<WpfToolkit:DataGrid ItemsSource= "{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContentControl},
Path=OperatorValues, Mode=TwoWay}" x:Name="ListValuesSearchControl">
<WpfToolkit:DataGrid.Columns >
<WpfToolkit:DataGridTextColumn Header="Lista valori" Width="Auto" Binding="{Binding Path=Item}"/>
</WpfToolkit:DataGrid.Columns>
</WpfToolkit:DataGrid>
</StackPanel>
</UserControl>
我的数据模板ListStringDataTemplate
不显示数据数据网格(显示类型名称),但请注意,如果我直接使用控件<basic:ListValuesSearch MinHeight ="740" x:Name="ListValues" />
而没有数据模板选择器工作正常。
我认为问题是这条路ItemsSource= "{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContentControl}, Path=OperatorValues, Mode=TwoWay}"
我可以解决这个问题,我错了吗?
谢谢
吨。