【发布时间】:2010-12-16 00:02:06
【问题描述】:
我有 3 张桌子: Item - 这是 DataContext - 它有一个导航列 Group 组 - 有一个导航列类别。
我希望在 DataGrid 中有两个(类别和组)列,当我选择一个类别时,它应该只在组列中显示 Category.Groups。
这是我正在处理的代码:
<tk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}">
<tk:DataGrid.Columns>
<!--Works-->
<tk:DataGridComboBoxColumn
Header="Categroy"
DisplayMemberPath="Title"
SelectedValuePath="CategoryId"
SelectedValueBinding="{Binding Group.Category.CategoryId}"
ItemsSource="{Binding Context.Categories,
Source={x:Static Application.Current}}"
/>
<!--Look at these two things:-->
<!--This does work-->
<tk:DataGridTemplateColumn>
<tk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl
ItemsSource="{Binding Group.Category.Groups}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type data:Group}">
<TextBlock Text="{Binding Title}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</tk:DataGridTemplateColumn.CellTemplate>
</tk:DataGridTemplateColumn>
<!--But this does NOT work, even it's the same source-->
<!--Notice I even tried a dummy converter and doesnt reach there-->
<tk:DataGridComboBoxColumn
Header="Group"
DisplayMemberPath="Title"
SelectedValuePath="GroupId"
ItemsSource="{Binding Group.Category.Groups,
Converter={StaticResource DummyConverter}}"
SelectedValueBinding="{Binding Group.GroupId}"
/>
</tk:DataGrid.Columns>
</tk:DataGrid>
更新
您会说问题是 ItemsSource 属性不能设置为非静态绑定吗?
我怀疑是这样,因为即使我使用DummyConverter 将 ItemsSource 设置为{Binding},它也不会在转换器中停止;并且在 Category ComboBox 中它工作正常。
【问题讨论】:
标签: wpf binding wpftoolkit datagridcomboboxcolumn