为什么 wpftoolkit 日期选择器会吃掉返回键按下事件?
我想知道是否有人知道为什么日期选择器会将标准键传递给任何父控件的按键向下路由事件,而不是返回键?
这是我写的xaml:
<WrapPanel Name="_wpParameters"
Grid.Row="0" Grid.Column="0"
Orientation="Horizontal"
Grid.IsSharedSizeScope="True"
Keyboard.KeyDown="_wpParameters_KeyDown" >
<!-- this is where the dynamic parameter controls will be added -->
</WrapPanel>
这是我用来检查返回键的代码:
private void _wpParameters_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
RaiseEvent(new RoutedEventArgs(LoadLiveResultsEvent, this));
}
}
我在意外时使用了按下键(本意是使用向上键),但我发现有趣的是标准数字和/字符正在触发逻辑,但不是返回键。任何想法为什么返回键不包含为按键键?
I am wondering if anybody knows why the datepicker will pass standard keys to any parent control's key down routed event, but not the return key?
here's the xaml i wrote:
<WrapPanel Name="_wpParameters"
Grid.Row="0" Grid.Column="0"
Orientation="Horizontal"
Grid.IsSharedSizeScope="True"
Keyboard.KeyDown="_wpParameters_KeyDown" >
<!-- this is where the dynamic parameter controls will be added -->
</WrapPanel>
Here is the code i was using to check for the return key:
private void _wpParameters_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
RaiseEvent(new RoutedEventArgs(LoadLiveResultsEvent, this));
}
}
I was using key down on accident (meant to use key up) but I found it interesting that the standard numeric and / characters were firing the logic, but not the return key. Any Idea's why the return key is not included as a key down key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如在 MSDN 上查看的......我的假设是控件正在消耗事件,并且可能将文本提交到可绑定源和其他清理,然后将事件标记为已处理。
As viewed on MSDN...my assumption is that the control is consuming the event and perhaps committing the text to the bindable source and other cleanup and then marking the event as handled.
另外不得不提一下我的解决方案。
我有一个父视图,它处理所有子视图模型中的 keyDown 事件。
我为 DatePicker、MaskedTextBox 等特殊控件声明了一种行为...捕获 PreviewKeyDown 隧道事件并引发 KeyDown 冒泡事件:
此行为分配给 datePicker:
由父视图侦听:
代码隐藏:
In addition had to mention my solution.
I had a parent view, that handle the keyDown event from all child viewmodels.
I declared a behavior for special controls like DatePicker,MaskedTextBox,etc... that catch previewKeyDown tunneling event and raise KeyDown bubbling event:
this behavior assigned to datePicker:
which is listened by parent view:
Code behind: