I want to implement my navigation in my WPF application. Currently the StartScreen.xaml is shown on startup, but when I click on the button the DeviceManagement.xaml is not shown. Not even the ShowDeviceManagement command is called.
This let me assume that the Command of the Button is not correct? How can I fix it?
App.xaml
<Application.Resources>
<DataTemplate DataType="{x:Type vm:DeviceManagementViewModel}">
<view:DeviceManagement />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:MainWindowViewModel}">
<view:StartScreen />
</DataTemplate>
</Application.Resources>
MainWindow.xaml
<Window ...>
<Window.DataContext>
<vm:MainWindowViewModel/>
</Window.DataContext>
<ContentControl
Content="{Binding ViewModel}">
</ContentControl>
</Window>
StartScreen.xaml
<UserControl ...>
<Button
Content="Click Me"
Command="{Binding DataContext.ShowDeviceManagement, RelativeSource={RelativeSource AncestorType={x:Type vm:MainWindowViewModel}}, Mode=OneWay}"/>
</UserControl>
MainWindoViewModel.cs
class MainWindowViewModel : ViewModelBase
{
public ViewModelBase ViewModel { get; set; }
public MainWindowViewModel()
{
ViewModel = this;
}
public ICommand ShowDeviceManagement
{
get
{
return new RelayCommand(action => ViewModel = new DeviceManagementViewModel());
}
}
}