WPF:如何在自定义控件中覆盖已加载的事件
我想在自定义控件中覆盖已加载的
事件,但我不知道该怎么做。
我想做这个示例,但是知道base.onloaded
不存在我不知道该怎么做
https://stackoverflow.com/a/28326029/14338640
您可以创建自定义控件并覆盖事件。参考 下面我尝试过用于文本框控件的代码。
class textboxex:textbox { 受保护的覆盖void ontouchup(system.windows.input.toucheventargs e) { base.ontouchup(e); } 受保护的替代void ontouchdown(system.windows.input.toucheventargs e) { base.ontouchdown(e); } }
有关信息,我的自定义控件从usercontrol
继承。
I would like to override the Loaded
event in my Custom control but I don't know how to do it.
I wanted to do like this example but knowing that base.OnLoaded
does not exist I don't know how to do it
https://stackoverflow.com/a/28326029/14338640
You can create a custom control and override the events. refer the
below code i tried for TextBox control.class TextBoxEx : TextBox { protected override void OnTouchUp(System.Windows.Input.TouchEventArgs e) { base.OnTouchUp(e); } protected override void OnTouchDown(System.Windows.Input.TouchEventArgs e) { base.OnTouchDown(e); } }
For information my custom control inherits from UserControl
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会“覆盖事件”。您覆盖方法或附加事件处理程序。
由于没有
on Loaded
替代方法,因此您唯一的选择是附加事件处理程序。You do not "override an event". You override a method or attach an event handler.
Since there is no
OnLoaded
method to override, your only option is to attach an event handler.