我有一个如下所示的文本框:
<TextBox Text="{Binding Stuff, UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding Path=LoadStuffCommand}" />
<KeyBinding Key="Enter" Command="SelectAll" />
</TextBox.InputBindings>
</TextBox>
当它运行时,只运行 SelectAll 命令。但是,如果我取出 SelectAll 行,则 LoadStuffCommand 运行良好。
显然,它正在用下一个命令替换命令(最后一个获胜)。但是我需要一种方法来运行我的命令并选择 TextBox 中的所有文本。
通常,我只会发出另一个命令来触发我的两个命令。但其中之一在我的 ViewModel 中,一个在我的 View 中。我怎样才能发出一个同时触发两者的命令? (有没有办法在 XAML 中创建命令?)
最佳答案
这可以通过 an aggregator 来完成.基本上,将命令分组到一个按顺序调用它们的对象中,并像一个命令一样绑定(bind)到该对象。
关于.net - KeyBinding 两个命令(一个在 VM 中,一个在 View 中)到一个键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11320298/