开发者

How to change DataGridComboBoxColumn's DataContext (WPF/C#)

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜