简体   繁体   中英

How to prevent datagrid from refreshing data?

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 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.

ie

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM