Summary of my question:
I am canceling from CollectionView's CurrentChanging event and ListBox still allows highlighting other items (even though the current position doesn't get changed. How can I prevent ListBox from highlighting other items?
More details:
I have a ListBox showing entities, synchronized with controls to edit it. IsSynchronizedWithCurrentItem is set to True. I have an ICollectionView object in my ViewModel to control how the data is sorted, navigated, etc.
On ICollectionView's CurrentChanging event I check if the current entity is "dirty" and if it is I cancel out the change (e.Cancel = true).
Suppose you highlight ListBox's item #2, make changes and click on item #3 without saving, the canceling of the position change works ok - CurrentItem stays intact and the edit controls don't change. However the ListBox highlights item #3!
What do I need to do to cancel out of the CurrentChanging event and prevent the ListBox from highlighting the other items except the CurrentItem?
private void OnCollectionViewCurrentChanging(object sender, CurrentChangingEventArgs e)
{
int currentPosition = collectionView.CurrentPosition;
if (IsInEditMode)
{
MessageBox.Show("Save or Cancel pending changes before selecting another one.");
e.Cancel = true;
collectionView.MoveCurrentToPosition(currentPosition);
}
}
As you can see I even tried saving the current position and using MoveCurrentToPosition, but this didn't help.
Thanks!