我的DataGrid被绑定到一个ObservableCollection<Entry>。
public class Entry
{
public List<string> Types {get; set;} = new List<string>() {"Type1", "Type2"};
}由于DataGrid.ItemsSource是Entry的集合,所以我希望单个DataGridRow的DataContext是typeof(Entry)。
<DataGrid ItemsSource="{Binding Entries}">
<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Border Width="100">
<StackPanel>
<ComboBox ItemsSource="{Binding DataContext.Entries[0].Types, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
<ComboBox ItemsSource="{Binding Types}" />
</StackPanel>
</Border>
</DataTemplate>
</DataGrid.RowHeaderTemplate>
</DataGrid>第一个Binding是工作的,第二个是无效的。
不过,我在Visual的BindingError Output-Window中没有获得任何信息。
我需要为每个Types显示Entry,这样通过索引的访问就不能工作了。
发布于 2017-12-12 15:14:54
这应该是可行的:
<ComboBox ItemsSource="{Binding DataContext.Types, RelativeSource={RelativeSource AncestorType=DataGridRowHeader}}" />https://stackoverflow.com/questions/47775689
复制相似问题