我正在尝试将 Command 绑定到TreeViewNode
. 为此,我拥有TextBlock
和行动,我在其中拥有Hyperlink
并Hyperlink
与命令绑定:
<HierarchicalDataTemplate DataType="{x:Type vm:TreeNodeViewModel}" ItemsSource="{Binding Path=Children, Mode=OneWay}">
<StackPanel Orientation="Horizontal" Margin="2 0 4 0">
<Image Width="18" Height="18" Margin="0 0 4 0" Source="{Binding NodeImage}"/>
<TextBlock>
<Hyperlink Command="{Binding Path=NodeActionCommand}" TextDecorations="None" Foreground="Black" Focusable="False">
<Run Text="{Binding Path=Name, Mode=OneWay}"/>
<!--Following Input binding is not working-->
<Hyperlink.InputBindings>
<KeyBinding Key="Enter" Command="{Binding Path=NodeActionCommand}"/>
</Hyperlink.InputBindings>
</Hyperlink>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
如果我鼠标单击节点,则此 XAML 工作,但在树命令节点上的键盘按键Enter
未触发。请帮忙。