I have a DataGrid template column with ComboBox. When I select a value and press enter the bound data is not updated (I see empty cell).
XAML:
<Window x:Class="WpfGrid2.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit"
>
<Window.Resources>
<x:Array x:Key="people" Type="sys:Object" />
<x:Array x:Key="knownLastNames" Type="sys:String">
<sys:String>Smith</sys:String>
<sys:String>Johnson</sys:String>
<sys:String>Williams</sys:String>
</x:Array>
</Window.Resources>
<StackPanel>
<dg:DataGrid x:Name="_grid" ItemsSource="{DynamicResource people}" CanUserAddRows="True" AutoGenerateColumns="False">
<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn Header="LastName" MinWidth="100">
<dg:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{DynamicResource knownLastNames}" SelectedItem="{Binding LastName}"></ComboBox>
</DataTemplate>
</dg:DataGridTemplateColumn.CellEditingTemplate>
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding LastName}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
<Button>test</Button>
</StackPanel>
</Window>
Code-Behind:
namespace WpfGrid2
{
public partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
List<Person> people = new List<Person>();
this.Resources["people"] = people;
}
}
}
If I change ComboBox to TextBox, it works fine
<TextBox Text="{Binding LastName}" />
What is wrong?