誰能告訴我爲什麼這個工作;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