开发者

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

开发者 https://www.devze.com 2023-03-08 11:28 出处:网络
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 myVie

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

精彩评论

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