
I've got something of a "best practices" question.
Consider a docking/MDI application, with an ActiveDocViewModel property for the currently-active document (tab). I update & RaisePropertyChanged for the ActiveDocViewModel in the PrimaryDocumentChanged event. The application also has a ToolWindow with its DataContext set to ActiveDocViewModel, such that its controls can be bound to properties of the ActiveDocViewModel, & whenever the doc tab changes, the controls are updated. One such control is an Int32EditBox:
<actiedit:Int32EditBox Minimum="1" Maximum="{Binding NumChannels}" Value="{Binding Path=Channel, UpdateSourceTrigger=PropertyChanged}" />
Now, imagine switching from a document tab where NumChannels=3 & Channel=3 to one where NumChannels=1 & Channel=1. What happens is when changing from Tab3 to Tab1, Tab3's Maximum gets set to 1, which forces Value down to 1, which updates the Channel value in the VM...*then* the tab actually changes. So the change from Tab3 to Tab1 appears to behave correctly (when viewing Tab1), but when we change back to Tab3, we see that channel has mysteriously changed from 3 to 1.
I've found that I can workaround this by doing something like the following in PrimaryDocumentChanged:
ActiveDocViewModel = null;
RaisePropertyChanged(() => ActiveDocViewModel);
ActiveDocViewModel = ea.Window.Content;
RaisePropertyChanged(() => ActiveDocViewModel);
...But somehow that feels a bit hacky. My question is: is there a suggested/graceful way to handle this type of scenario?