I have a WPF application with multiple views. I want to switch from view 1 to view 2 and from there I can switch to multiple views. So I want a button on view 1 that loads v
Maybe this link will help you. Just set the NavigateTo
property to the view which you need to display on the window.
As an example you can do something like
Then the class file would be
public partial class MainWindowView : Window
{
public MainWindowView()
{
InitializeComponent();
}
public ContentControl ViewContainer { get { return _viewContainer; } }
}
Then you can define each view as UserControl
and then using the link I gave above bind the button's meffed:NavigationExtensions.NavigateTo="secondView"
. To target the ContentControl
of the Window
just use a RelativeSource
binding. For e.g
meffed:NavigationExtensions.NavigationHost="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}},Path=ViewContainer}"
In each of the view just see that you annotate the code behind class definition with the [NavigationView("firstview")]
and so on.
It is complicated for first time but it will be very easy once you understand the idea.