数据网格中的组合框未正确更新

时间:2011-03-03 18:28:53

标签: c# wpf

我将一个组合框选择的索引绑定到我的viewmodel中的整数值(Mode)。它似乎工作,除非我尝试更改组合框中的值时,它不会更改所选的索引/值。

的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");
        }
    }

1 个答案:

答案 0 :(得分:0)

原来我需要一个Cell模板和一个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>
相关问题