在自定义控件中捕获点击事件[已解决] [英] Capture the Click Event in a Custom Control [SOLVED]

查看:126
本文介绍了在自定义控件中捕获点击事件[已解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从Button继承的WPF自定义控件.

如何以编程方式获取自定义控件以捕获Click事件(以便我可以记录操作并进行一些内部工作)
(基本上,我想捕获事件并将某个属性设置为某个值),并将其作为类的一部分成为标准功能.

从我的理解来看,自定义控件应该能够捕获它自己的偶数并做一些工作.

I have a WPF Custom Control inherited from Button.

How do I programatically get the custom control to capture the Click Event (so that I can record the action and do some internal work)
(basically I want to catch the event and set a certain property to a certain value) and make this part of the classes standard functionality.

From my understanding the custom control should be able to catch it''s own even and do some work.

推荐答案

已解决

我意识到为什么会有问题.

我看不到Click事件

这是因为我在类声明中还不够明确:

我放了
Solved

I have realised why I had a problem.

I could not see the Click event

This was because I was not explicit enought in my class declaration:

I put
public class StateButton : Button


显然选错了按钮


obviously picked the wrong button

public class StateButton : System.Windows.Controls.Button


这有效

然后我只是覆盖事件


This works

Then I just override the event


这篇关于在自定义控件中捕获点击事件[已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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