我在从 DataGrid 中访问 Window 的 DataContext 时遇到了一些问题。
DataGrid 绑定到 IBindingList:
public IBindingList Items{ get; set; }
private void initItems()
{
//ItemFactory is a Linq2SQL Context, Items is the view of availabe Items
this.Items = this.ItemFactory.Items.GetNewBindingList();
}
从我的 xaml 中,我尝试获取这些数据来填充 ComboBox:
<DataGridComboBoxColumn Header="Typ"
DisplayMemberPath="Description"
SelectedValuePath="ItemID"
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Mode=OneWay, Path=DataContext.Items, UpdateSourceTrigger=PropertyChanged}" />
但它不起作用。我已经尝试了很多变种。ComboBox 未被填充。
非常感谢任何帮助!
笔记:
同一窗口中的以下 ComboBox 确实有效:
<ComboBox x:Name="workingCombo" ItemsSource="{Binding Path=Items}" DisplayMemberPath="Description" SelectedValuePath="ItemID" />