I had a quick look at your github code and it is incomplete. ViewModels are missing. So I could not run your code to see what you are trying to do.
Looking at the code above, you're trying to navigate by ViewModel.
Here is your code for the
MainWindow
:
<UserControl>
<Grid Background="{StaticResource ViewMainBackGroundBrush}">
<Border Style="{StaticResource ViewItemBorder}">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Foreground="White" Text="Main View" />
</Grid>
</Border>
</Grid>
</UserControl>
You currently have not implemented the host for your ViewModels to display any views. You need to implement something like this:
<Window x:Class="app.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="page name goes here" Height="900" Width="1200">
<ContentControl Content="{Binding CurrentViewModel}" />
</Window>
and the code behind would look something like this:
public partial class MainWindow
{
public MainWindow(IMainViewModel viewModel)
{
this.DataContext = viewModel;
this.InitializeComponent();
}
}
And your
MainViewModel
to change views would be something like this:
public class MainViewModel : NavigationViewModelBase, IMainViewModel
{
public MainViewModel(INavigationStore navigationStore) : base(navigationStore)
{
}
}
public abstract class NavigationViewModelBase : ViewModelBase
{
private readonly INavigationStore _navigationStore;
public ViewModelBase CurrentViewModel => this._navigationStore.CurrentViewModel;
protected NavigationViewModelBase(INavigationStore navigationStore)
{
this._navigationStore = navigationStore;
this._navigationStore.CurrentViewModelChanged += this.OnCurrentViewModelChanged;
}
private void OnCurrentViewModelChanged() => this.OnPropertyChanged(nameof(this.CurrentViewModel));
}
INavigationStore
is just a way of passing the
CurrentViewModel
that you wish to display from your navigation / SideMenu.