Currently I'm catching the SelectionChanged event, but I would prefer to catch an eariler event that will allow me to cancel the selection change.
Background:
I have two data grids, the lower being a detail of the upper. When the upper changes, I currently prompt the user to save changes. But if there are validation errors, I w开发者_运维知识库ant to offer them the option to cancel the selection change and fix those errors.
You can try binding the upper grid's ItemsSource
an ICollectionView
as follows.
var items = CollectionViewSource.GetDefaultView(*your current bound collection* );
items.CurrentChanging += this.OnCurrentItemChanging;
*your grid*.ItemsSource = items;
Then inside OnCurrentItemChanging, you can make e.Cancel = true
which will cancel the selection change.
精彩评论