语言

ButtonBase.Click 活动

定义

单击按钮控件时发生。

// Register
event_token Click(RoutedEventHandler const& handler) const;

// Revoke with event_token
void Click(event_token const* cookie) const;

// Revoke with event_revoker
ButtonBase::Click_revoker Click(auto_revoke_t, RoutedEventHandler const& handler) const;
public event RoutedEventHandler Click;
function onClick(eventArgs) { /* Your code */ }
buttonBase.addEventListener("click", onClick);
buttonBase.removeEventListener("click", onClick);
- or -
buttonBase.onclick = onClick;
Public Custom Event Click As RoutedEventHandler 
<button Click="eventhandler"/>

事件类型

示例

以下示例演示如何处理 Click 事件并设置从 ButtonBase 继承的 Button 的 IsEnabled 属性。

<StackPanel>   
    <Button Content="Submit" 
            Click="submitButtonClick"/>
    <TextBlock x:Name="textBlock1"/>
</StackPanel>
void submitButtonClick(object sender, RoutedEventArgs e)
{
    textBlock1.Text = "You clicked the Submit button.";
}

注解

还有一个 UIElement.Tapped 事件,该事件指示已使用指针设备(如鼠标或触摸)按下并释放元素。 但是,建议 Click 将此事件用作已单击按钮的常规用途通知,因为它也会响应已使用键盘或辅助功能工具单击的按钮。

适用于

另请参阅