2011-03-03 21 views
0

我在我的viewmodel中将组合框的选定索引绑定到整数值(Mode)。它似乎工作,除非我尝试更改组合框中的值,它不会更改选定的索引/值。DataGrid中的组合框未正确更新

的XAML:

<DataGridTemplateColumn.CellTemplate> 
    <DataTemplate> 
     <ComboBox 
      ItemsSource="{Binding Source={StaticResource modeValues}}" 
      SelectedIndex="{Binding Mode, Mode=TwoWay}" 
      /> 
    </DataTemplate> 
</DataGridTemplateColumn.CellTemplate> 

public int Mode 
    { 
     get { return _mode; } 
     set 
     { 
      _mode = value; 
      NotifyPropertyChanged("Mode"); 
     } 
    } 
+0

当你说它不会改变“选定的索引/值”是你指的ViewModel或别的什么?当您更改组合框选择时,ViewModel上的Mode属性将改变。你是否期待不同的行为? – 2011-03-03 18:48:28

+0

我的意思是网格中组合框的值 – user404068 2011-03-03 20:48:11

回答

0

原来我需要一个电池模板和CellEditingTemplate。

<DataGridTemplateColumn.CellTemplate> 
        <DataTemplate> 
         <TextBlock Text="{Binding ModeText}"/> 
        </DataTemplate> 
       </DataGridTemplateColumn.CellTemplate> 
       <DataGridTemplateColumn.CellEditingTemplate> 
        <DataTemplate> 
         <ComboBox 
          ItemsSource="{Binding Source={StaticResource modeValues}}" 
          SelectedIndex="{Binding Mode, Mode=TwoWay}" 
         /> 
        </DataTemplate> 
       </DataGridTemplateColumn.CellEditingTemplate> 
      </DataGridTemplateColumn>