2011-05-25 82 views
-2

我正在使用MVVM与WPF,Window.DataContext设置为myViewModel。现在,我在DataGrid中有DataGridComboBoxColumn,我想将此列的ItemsSource设置为myViewModel的某些属性。如何更改DataGridComboBoxColumn的DataContext(WPF/C#)

这怎么办?

+0

[WPF中其他的ItemsSource(http://stackoverflow.com/questions/6122279/other-itemssource-in-wpf) – biju 2011-05-25 10:53:45

回答

0

你可以做这样的事情

<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

遗憾的是没有可能的重复。 YourCollectionProperty是CURRENT ROW的属性,而不是主模型的属性。 – Cartesius00 2011-05-25 10:26:06

+0

对不起,我没有正确理解这个问题 – 2011-05-25 10:53:24

相关问题