我有一個文本框,併爲該文本框添加了一個keydown事件。一切工作正常,但我只注意到,當我按'Backspace'和'Delete'鍵時,綁定命令沒有被調用。TextBox KeyDown觸發器事件不適用於退格鍵和刪除鍵
我查看XAML文件: -
<TextBox x:Name="textBox" Width="500" Text="{Binding TextBoxText, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<cmd:EventToCommand Command="{BindingPath=TextBoxKeyDownEvent}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
我的視圖模型CS文件: -
//TextBox Key Down Event Handler
private DelegateCommand _textBoxKeyDownEvent;
public ICommand TextBoxKeyDownEvent
{
get
{
if (_textBoxKeyDownEvent == null)
{
_textBoxKeyDownEvent = new DelegateCommand(TextBoxKeyDownEventHandler);
}
return _textBoxKeyDownEvent;
}
set { }
}
有人可以給我一些建議
的'EventToCommand'是你需要挖成一個黑箱。 – 2014-09-27 09:21:33
你可以使用KeyBinding - 但你的TextBoxText屬性更新我猜。爲什麼在文本更改時收到通知時需要捕獲密鑰? – 2014-09-27 09:37:41
@kallocaion:謝謝你的回答。伯我的情況綁定textProperty將無法正常工作。因爲程序會動態改變文本框的內容,然後我不想調用我的eventHandler。我有其他事件與相同的組件相關聯,並且我無法切換到其他事件,如鍵控。 – ifti24 2014-09-27 09:57:15