Reputation: 2489
I am using WPFToolKit DataGrid in my application. I have bound the DataGrid to a XMlDocument. The grid displays the Data from XML. I have to remove all the bindings in DataGrid and reset it during some event.
Now my question is how do I remove the DataBinding between DataGrid and XMLDocument.
I have tried something like this ::
dg.SetValue(DataGrid.BindingGroupProperty, null); //doesn't work
What am I doing wrong?
Upvotes: 2
Views: 10883
Reputation: 87
The above didn't work for me. What works for me if binding:
dataGrid.ItemsSource = null;
dataGrid.Columns.Clear();
dataGrid.Items.Clear();
dataGrid.Items.Refresh();
If not binding:
dataGrid.Columns.Clear();
dataGrid.Items.Clear();
dataGrid.Items.Refresh();
Upvotes: 0
Reputation: 2489
The following line solved my problem ::
BindingOperations.ClearAllBindings(dg);
Upvotes: 2
Reputation: 34240
To undo a binding in WPF, simply set the property that was previously bound to a some other value. In the case of DataGrid
, its data is usually bound to the ItemsSource
property so setting that to null will remove its previous binding. But if you have any other properties in the DataGrid
that are bound, you will have to set those to "unbound" values as well. Which ones will depend on your situation. But in your example the code would be:
dg.ItemsSource = null;
Upvotes: 6