I have a WPF-Application with two windows as Views (MVVM). With the first one binding of commands works out quite fine though with the 2nd view commands don't trigger (both windows access the same viewmodel). It doesn't matter if they are binded to a button or a key event etc. One thing I've notice; In the properties box the command binding isn't visible in the command textbox though it should be I guess.
Another thing to mention: the 2nd window/view will show after a button click from the first view + the first window is still visible. The Datacontext will be also delegated to the 2nd view.
Here a sequence of my code:
<Window
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"
xmlns:vm="clr-namespace:Lobpreis.ViewModels"
xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic" x:Class="Lobpreis.Views.LiederlisteView"
mc:Ignorable="d"
Title="LiederlisteView" WindowStyle="SingleBorderWindow" Height="450" Width="800" >
<Window.DataContext>
<vm:ShellViewModel/>
</Window.DataContext>
<Window.InputBindings>
<KeyBinding Key="Down" Command="{Binding PressKeyDown}" />
<KeyBinding Key="Up" Command="{Binding PressKeyUp}" />
</Window.InputBindings>
<Grid > etc...
This is how I handled the transfer of the Datacontext:
LiederlisteView MeineLiederlisteView = new LiederlisteView();
MeineLiederlisteView.DataContext = this;
MeineLiederlisteView.ShowDialog();
MeineLiederlisteView.Focus();
You're trying to bind the 2nd view's DataContext to the 1st view not 1st view's DataContext.
Try to replace
MeineLiederlisteView.DataContext = this;
with
MeineLiederlisteView.DataContext = this.DataContext;