开发者

Combo box in datagrid not updating correctly

I am binding a combobox selected index to an integer value (Mode) in my viewmodel. It seems to work except when I try to change the value in the combobox it will not change the selected index/value.

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


Turns out I needed a Cell template and a 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>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜