Here's the scenario:
- Two toolkit data grids, side-by-side
- Grid A is readonly and cannot be changed
- Grid B's contents can be changed and saved using a save button under it
I开发者_StackOverflow need Grid A to stay the same until the user clicks the save button, regardless of any changes Grid B may or may not have. When I bind to the property below both grids change when Grid B changes. I want to avoid this.
What's the best approach to do this? Both grids are currently binding to the below property:
public EntitySet<SomeEntity> SomeEntities
{
get { return _entity; }
set
{
if (_entity != value)
{
_entity= value;
OnPropertyChanged("SomePropertyChanged");
}
}
}
Set the binding for Grid A to OneTime.
i.e.
Text="{Binding Path=Age, Mode=OneTime}"
Maybe instead of completely switching out the collection of SomeEntities that the Grid is binding to, maybe use an ObservableCollection, then update on a per item basis in the ObservableCollection. Then use the Mode=OneTime that Derek mentions.
You can create two EntitySets, one for each DataGrid. After saving, you have to update set binded to read-only DataGrid.
Got it to work by using a DataGridTemplateColumn with OneTime binding. For example,
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Enabled, Mode=OneTime}"></TextBlock>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
精彩评论