WPF窗口中的命令绑定和输入绑定 [英] Command Binding and Input Binding in WPF Window

查看:183
本文介绍了WPF窗口中的命令绑定和输入绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有很多WPF窗口,因此我为窗口创建了样式.

I have many WPF windows in my Project and so i created a style for window.

<Style x:Key="JIMSWindow" TargetType="Window">
    <setter property="ResizeMode" value="NoResize" />
    <setter property="ShowInTaskbar" value="False" />
    <setter property="SizeToContent" value="WidthAndHeight" />
    <setter property="Background" value="Transparent" />
    <setter property="WindowStyle" value="None" />
    <setter property="BorderThickness" value="0" />
    <setter property="AllowsTransparency" value="True" />
</Style>



我想做这种风格的事情,然后将命令传递给一些逻辑,以便在我按Esc键时可以关闭窗口.

我的目的是当我按esc键时关闭窗口.



I want to do something in this style and then passing the commands to some logic where i can close the window on escape key press.

My aim is to close the window when i press a esc key

推荐答案

问题是您正在谈论事件(KeyDown等).您需要一个事件的事件处理程序,而该事件处理程序无法通过样式完成.

您可能可以模板化某些东西,然后使用System.Windows.Interactivity将事件绑定到GalaSoft EventToCommand对象.
The problem is you are talking about an event (KeyDown etc.). You need an event handler for an event and that can not be done via styles.

You might be able to template something and use the System.Windows.Interactivity to bind the events to the GalaSoft EventToCommand object.


这篇关于WPF窗口中的命令绑定和输入绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆