I am using MVVM with WPF, Window.DataContext
is set to myViewModel
. Now, I have DataGridComboBoxColumn
in the DataGrid and I would like to set the ItemsSource
for this column to some property of myViewModel
.
How can this b开发者_Go百科e done?
You can do something like this
<DataGridComboBoxColumn >
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="ItemsSource" Value="{Binding Path=DataContext.YourProperty, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
精彩评论