Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'll have to do a little bit guessing here, as I don't really know the architecture of your program. I'm going to assume you have two Windows classes: <strong>MainWindow</strong> and <strong>SideWindow</strong>, and a single view model class <strong>AppVm</strong>. You'll have to adapt if you have a different settings.</p> <p>The simplest solution would be to bound the <strong>WindowState</strong> of both windows to a single property in the ViewModel. Make sure the property fires notifications.</p> <p>The View Model class:</p> <pre><code>class AppVm : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private WindowState m_state; public WindowState state { get { return m_state; } set { m_state=value; raise("state") } } private raise(string propname) { PropertyChanged(this, new PropertyChangedEventArgs(propname)); } .... } </code></pre> <p>Now, in the Windows XAML files, bind the WindowState to the one on the view model:</p> <pre><code>&lt;Window ... WindowState="{Binding Path=state,Mode=TwoWay} ...&gt; </code></pre> <p>Note how I set the mode to TwoWay. This ensure that when the state is changed when the using clicking the minimize Window, it will also change the value in the VM. That's all.</p> <p>Now, if your architecture differs, you'll have to adapt. It isn't clear what you want to do when the user maximize one of the windows (do you even allow it). If you have two different view model classes for each Window, you can write down a more complex path, assuming one view has a reference to the other view, save the stae variable only in the inner class, then the binding statement can be: Path=OtherVm.state.</p> <p>If your View logic is more complex, It is OK to have some code behind in the view (*.xaml.cs files). The only rule is that the View Model shouldn't be "aware" of the view (theoritically, the VM can also run a "unit test view"). You can subscribe to the event StateChanged of the View and write down your logic there. Anyway, the cleanest solution is described in the sample code above.</p> <p>Hope this helped.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload