在我的WPF应用程序中,我有一个TextBox
,其上有KeyBinding
和KeyTrigger
,但似乎没有调用KeyTrigger
。
MainWindow.xaml
<Window
x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
Title="MainWindow" Height="350" Width="525">
<TextBox>
<TextBox.InputBindings>
<KeyBinding Key="Return" Command="{Binding LogCommand}" CommandParameter="from KeyBinding"/>
</TextBox.InputBindings>
<i:Interaction.Triggers>
<ei:KeyTrigger Key="Return">
...
</ei:KeyTrigger>
</i:Interaction.Triggers>
</TextBox>
</Window>
有没有办法调用它们?我想这样做是因为在ViewModel中有一些我不想做的事情。
答案 0 :(得分:1)
只需将两者放入interaction.Triggers部分并删除直接输入绑定:
<TextBox>
<i:Interaction.Triggers>
<ei:KeyTrigger Key="Return">
<i:InvokeCommandAction Command="{Binding LogCommand}" CommandParameter="from KeyBinding"/>
...
</ei:KeyTrigger>
</i:Interaction.Triggers>
</TextBox>