Есть главное окно - MainWindow. В него вложена View. И в эту View вложена ещё одна ChildView. Приложение сделано по паттерну MVVM.
Как это выглядит: (MainWindow)
<Window.DataContext>
<vm:RootVM />
</Window.DataContext>
<ContentPresenter Content="{Binding CurrentContentVM}"/>
View
<UserControl x:Class="SubstationDirectory.V.SubstationEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SubstationDirectory.V"
xmlns:cs="clr-namespace:SubstationDirectory.Converters"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" x:Name="RootElem">
<UserControl.InputBindings>
<KeyBinding Key="Enter" Command="{Binding UpdateSubstation}"/>
</UserControl.InputBindings>
<Grid>
<local:Alert Grid.Row="0" DataContext="{Binding ElementName=RootElem, Path=DataContext.UpdateAlert}" Visibility="{Binding Converter={StaticResource VisibilityFromObjectIsNull}, ConverterParameter=false}" />
</Grid>
ChildView
<UserControl x:Class="SubstationDirectory.V.Alert"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SubstationDirectory.V"
xmlns:cs="clr-namespace:SubstationDirectory.Converters"
mc:Ignorable="d"
Name="RootElem">
<UserControl.InputBindings>
<KeyBinding Key="Enter" Command="{Binding MainAction}"/>
</UserControl.InputBindings>
</UserControl>
Задача
Нужно привязать кнопку Enter к команде ChildView.
Как видно, я попытался сделать это при помощи InputBindings
. Но это не сработало. Во View сделана привязка тоже. Но там все работает.
Вопрос
Как сделать, чтобы привязка к клавише в ChildView заработала?
Visiblity стал равен
Visible` в рамках MVVM?