在没有代码隐藏的情况下挂接keydown事件有一点问题!
所以,我们有组合框
<ComboBox Height="20" Width="auto"
ItemsSource="{Binding AlignComboItems}"
SelectedValue="{Binding SelectedComboItem, Mode=TwoWay}"
SelectedValuePath="Key" DisplayMemberPath="Value"
SelectedItem="{Binding SelectedItem}"
x:Name="cmbBoxAlign">
</ComboBox>
和一些TextBox。
<TextBox Text={Binding SomeSource}></TextBox>
如何在TextBox上捕获keydown事件以选择(例如)ComboBox中的最后一个元素?我不能使用TextBox DataSource属性更改,因为需要将用户输入连接起来。
最佳答案
如果您不介意安装Expression Blend SDK,则应该可以在文本框中执行此操作
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<i:InvokeCommandAction Command="{Binding Path=TheCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
在xaml中添加对
System.Windows.Interactivity
和以下 namespace 的引用后xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
链接到Expression SDK for 4.0
http://www.microsoft.com/en-us/download/details.aspx?id=10801
关于wpf - 在TextBox(MVVM)中挂接 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14842580/