访问Combobox.ItemSource性质,如果我使用如何内DataGridTemplateColumn
comboboxColumn1.ItemsSource = comboboxSource;
如果我现在用DataGridTemplateColumn,而不是有DataGridComboBoxColumn在XAML
<DataGridComboBoxColumn Header="Department Id" x:Name="comboboxColumn1"
可以参考我的comboboxColumn1.Itemsource代码。 ..
<DataGridTemplateColumn x:Name="Col2" Header="name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="Combobox2" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
然后,我该如何在代码中设置Combobox2.ItemSource ?
由于单个对象这样做的原因 - 现在我已经尝试使用设置的ItemsSource在XAML'< ComboBox ItemsSource =“{Binding comboBoxSelections}”/>'其中comboBoxSelections在MainWindow中定义为'public Dictionary comboBoxSelections;' - 即使comboBoxSelections包含项目,组合框也是空的。任何线索为什么? –
user3357963
@ooo您需要更改绑定的来源,告诉它在您的MainWindow而不是DataGrid项目中查找属性。你可以给你的MainWindow一个'x:Name'并在你的绑定中使用'ElementName = MyWindowName',或者在绑定中使用'RelativeSource = {RelativeSource AncestorType = {x:Window}}'来告诉它查找VisualTree为一个Window对象 – Rachel