Handling Min/Max/Value When Changing Document Tabs

Docking/MDI for WPF Forum

Posted 7 years ago by Justin Klein
Version: 17.1.0650
Avatar

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?

Comments (4)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Justin,

What's happening is that setting the Maximum, kicks in OnMaximumPropertyValueChanged logic that in this case alters Value.

I think one way to work around it might be to flip the order you define the properties in XAML.  Maybe change it so Value appears before Minimum and Maximum.  Give that a try.


Actipro Software Support

Posted 7 years ago by Justin Klein
Avatar

Nope, swapping the attributes still yields the same issue/behavior... :/

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Justin,

When I tried flipping their order in XAML in a small test I made, it worked for me.  If it's not for you, could you please make a new simple sample project that shows it and email that to our support address?  We will debug it with that.  Please exclude the bin/obj folders from the ZIP and rename the .zip file extension so it doesn't get spam blocked.  Reference this thread in your email too.  Thanks!

[Modified 7 years ago]


Actipro Software Support

Posted 7 years ago by Justin Klein
Avatar

Thanks, sent.

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.