简体   繁体   English

如何在扩展的Button控件中隐藏Click事件?

[英]How to suppress the Click event in extended Button control?

I have a custom button in my Windows Phone application. 我的Windows Phone应用程序中有一个自定义按钮。 The button overrides the OnClick method to prevent a regular click routine: 该按钮将覆盖OnClick方法,以防止执行常规的单击例程:

protected override void OnClick()
{
    if(ProgressBar != null
        && DelayDuration.HasValue
        && DelayDuration.Value.HasTimeSpan
        && DelayDuration.Value.TimeSpan > TimeSpan.Zero)
    {
        // Suppress the default click action
        return;
    }

    base.OnClick();
}

Now I need to convert my app to the Windows Store one. 现在,我需要将我的应用程序转换为Windows应用商店之一。 But the Button class doesn't have the OnClick method! 但是Button类没有OnClick方法! How can I extend Button behavior from the derived control? 如何扩展派生控件中的Button行为?

There is Click event for Button. 按钮有Click事件。 http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.primitives.buttonbase.click.aspx http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.primitives.buttonbase.click.aspx

You can override button's OnTap method in Windows Phone or Windows Store application 您可以在Windows Phone或Windows Store应用程序中覆盖按钮的OnTap方法

protected virtual void OnTapped(
  TappedRoutedEventArgs e
)

and set e.Handled = true if you want to prevent event tunneling. 如果要防止事件隧道e.Handled = true ,请设置e.Handled = true

For all practical purposes, the Tap and Click events are equivalent for a Button. 出于所有实际目的,Tap和Click事件等效于Button。

The Click event was originally defined in Silverlight for desktop Windows and it is only defined for the Button control (and derivatives such as HyperlinkButton). Click事件最初是在Silverlight中为台式机Windows定义的,仅为Button控件(及其派生类,例如HyperlinkBut​​ton)定义。 You can think of the Click event as the "traditional" way to handle a Button press. 您可以将Click事件视为处理按钮按下的“传统”方式。

The Tap event was added to the framework in Windows Phone 7.1 (Mango). Tap事件已添加到Windows Phone 7.1(Mango)中的框架中。 Tap is defined in the UIElement class, which is the parent of many types of controls. Tap在UIElement类中定义,该类是许多类型的控件的父级。 You can handle a Tap event in a TextBlock, Image, and many other controls. 您可以在TextBlock,Image和许多其他控件中处理Tap事件。 Button is subclassed from UIElement as well, and thus can also receive Tap events. Button也是UIElement的子类,因此也可以接收Tap事件。 It is redundant that a Button can receive both Tap and Click events. Button可以同时接收Tap和Click事件是多余的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM