I'm extremely new to WPF and the MVVM ideology, and am in the process of creating an app with it. So to my understanding, from reading this WPF-MVVM Pattern Guide, we have:
- a Window, which facilitates the navigation between Views via Relay Commands,
- some Views, which are XAML files that, when interacted with in a certain way (like pressing a button), uses a Command to call a method in
- our ModelViews, which handle most of the logic of the View.
To switch from View1 to View2, in View 1 we might have a Command attached to a button that tells us to load View2,
VIEW1
<StackPanel>
Button<
Command="{Binding DoSomeWorkInModalView1}"
/>
</StackPanel>
<StackPanel Visibility="{Binding VariableInModalView1ThatNeedsToBeSet, Converter={StaticResource BooleanToVisibilityConverter}}">
Button<
Command="{Binding MethodThatLoadsView2}"
/>
</StackPanel>
MODALVIEW1
DoSomeWorkInModalView1(){
//Doing some work here...
VariableInModalView1ThatNeedsToBeSet = true;
}
or something to that effect. After we press a button, ViewModal1 does some work and sets VariableInModalView1ThatNeedsToBeSet
to true, so we can see our button and can now press it to go to View2. Great, all of this works in my application.
What I need to do is when this StackPanel becomes visible, call MethodThatLoadsView2
without having to press a button. In other words, as soon as VariableInModalView1ThatNeedsToBeSet
is set to true, we load View2 instead of waiting on the user to press a button, kind of like how in React, useEffect() can be used to perform some logic as soon as the component is loaded.
Sorry if this is a little vague, let me know if you have any questions. Thanks!