【发布时间】:2011-03-24 21:09:46
【问题描述】:
我在从 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 x:Name="workingCombo" ItemsSource="{Binding Path=Items}" DisplayMemberPath="Description" SelectedValuePath="ItemID" />
【问题讨论】:
标签: wpf data-binding binding datagridcomboboxcolumn