关闭、最小化和最大化事件在自定义 WPF 表单模板中不起作用
我正在使用控件模板在 WPF ResourceDictionary 中设计自定义表单,以便稍后可以轻松使用该窗口。我正在使用 Expression Blend 进行设计,并且一直致力于让关闭、最大化和最小化按钮正常工作。
起初我无法访问任何事件,但是 这个 stackoverflow问题帮助我将类绑定到资源字典。当我尝试访问关闭、最小和最大按钮的单击事件时,我进入代码编辑器并显示 btn_Close 事件处理程序。
当我尝试编译时,出现错误“application.Resources 不包含 close (...) 的定义”(Resources 是类的名称) (当我输入“this.”时,智能感知给了我很多命令,但没有提供 .Close)
我很确定类和 XAML 中的所有命名空间都是正确的,如何才能使其正常工作?或者我是否需要为使用此模板的每个表单单独编码?
I'm designing a custom form in a WPF ResourceDictionary using a controltemplate so I can easily use the window later on. I'm designing it with Expression Blend and I'm stuck on getting the close, maximize and minimize buttons to work.
At first I wasn't able to access any of the events, however this stackoverflow question helped me with binding a class to the resourcedictionary. When I try to access the click event for the close, min and max buttons, I get in the code editor and the btn_Close eventhandler shows up.
When I try to compile it gives me the error "application.Resources doesn't contain a defition for close (...)" (Resources is the name of the class)
(when I type "this." intellisense gives me many commands but not .Close)
I'm pretty sure all of the namespaces in both the class and XAML are right, how do I get this working properly? Or do I need to code this seperately for each form that uses this template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您安排的奇怪情况中,代码隐藏中的
this
并不引用Window
而是引用ResourceDictionary
。然而,事件发生时将由窗口生成,因此您需要将sender
参数强制转换为Window
,而不是使用this
并而是关闭
。In the strange situation you've arranged,
this
in the code-behind does not refer to aWindow
but to theResourceDictionary
. Nevertheless, the event when it occurs will be generated by a window so instead of usingthis
you need to cast thesender
parameter to aWindow
andClose
that instead.