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>
精彩评论