Reputation: 561
I have implemented a DataGrid that way:
<DataGrid
x:Name="MyDataGridFilter"
ItemsSource="{Binding}"
IsSynchronizedWithCurrentItem="True"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn
x:Name="FilterTextCol01">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox
Grid.Column="0"
IsHitTestVisible="True"
Text="{Binding Path=FilterTextCol01}" />
<CheckBox
Grid.Column="1"
x:Name="FilterAktivTextCol01"
IsHitTestVisible="True"
IsChecked="{Binding Path=FilterAktivTextCol01}"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
The binding in the Code goes this way:
FilterItemsList = new ObservableCollection<DataGridFilterEntity>();
MyDataGridFilter.DataContext = FilterItemsList;
(it is shorted) FilterItemsList is implemented as an INotifyPropertyChanged clas:
public class DataGridFilterEntity : INotifyPropertyChanged
With the member FilterTextCol01 (of course):
public string FilterTextCol01
{
get { return _FilterTextCol01; }
set
{
_FilterTextCol01 = value;
Changed("FilterTextCol01");
}
}
Everything works fine. When I change the FilterItemsList the DataGrid refelcts these changes. But when I make some changes in the UI (in the DataGrid) it isn't reflected by the ObservableCollection (FilterItemsList).
I searched and tried some hours but did not find any solution. Does anyone know how to solve this? Thank you!
Upvotes: 1
Views: 2413
Reputation: 19885
What kind of changes are you doing to the GUI? Are you updating the Text
of the TextBox
and checking the CheckBox
?
If so the same example works in my case. I receive the updated text and checked boolean back in my model when I focus off the textbox or checkbox.
Upvotes: 0
Reputation: 1435
You need TwoWay binding.
For example,
<TextBox
Grid.Column="0"
IsHitTestVisible="True"
Text="{Binding Path=FilterTextCol01, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<CheckBox
Grid.Column="1"
x:Name="FilterAktivTextCol01"
IsHitTestVisible="True"
IsChecked="{Binding Path=FilterAktivTextCol01, Mode=TwoWay}"/>
Upvotes: 1