谁能告诉我为什么这个工作;WPF Datagrid ComboBox DataBinding
<DataGridTemplateColumn Header="Supplier">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="SupplierName" SelectedValuePath="SupplierID"
SelectedValue="{Binding SupplierID}"
ItemsSource="{Binding Path=DataContext.Suppliers, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
但是这并不是;
<DataGridComboBoxColumn Header="Combo" DisplayMemberPath="SupplierName" SelectedValuePath="SupplierID"
SelectedValueBinding="{Binding SupplierID}"
ItemsSource="{Binding Path=DataContext.Suppliers, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" />
二片段不会显示在编辑SupplierName列表...
发现ElementName似乎没有工作出于同样的原因,并且Path = Suppliers不起作用,因为DataGrid的DataContext已经绑定到行集合。结束了DataTemplates,并使用MultiBinding&a Converter在非编辑模式下显示名称。无论如何,你回答*为什么*它不起作用是正确的:) – 2010-11-09 01:07:18