[英]uwp: how to pass Button click event to default handler
I would like to handle the Button Click event, do something, and then let the default handler execute.我想处理 Button Click 事件,做一些事情,然后让默认处理程序执行。
Here's what I have:这是我所拥有的:
<Button ... Click="OnMoreClicked" />
And here's my handler这是我的处理程序
void onMoreClicked (object sender, RoutedEventArgs e)
{
... do something ...
... continue with default button handler ...
}
EDIT:编辑:
The button activates a flyout, thus it already has a handler to do that and I want to ensure that handler gets executed.该按钮激活一个弹出,因此它已经有一个处理程序来执行此操作,我想确保该处理程序被执行。
EDIT 2: my example code was too minimal.编辑 2:我的示例代码太少了。 See this, instead:
看到这个,而不是:
<Button ... Click="onMoreClicked">
<Button.Flyout >
...
</Button.Flyout>
</Button>
And和
public void onMoreClicked (object sender, RoutedEventArgs e)
{
... do something ...
... call default handler to show flyout ...
}
The Click
event handler is called before the Flyout
is shown.在显示
Flyout
之前调用Click
事件处理程序。
So you for example change the Background
of the Button
in the event handler:例如,您可以在事件处理程序中更改
Button
的Background
:
private void onMoreClicked(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
button.Background = new SolidColorBrush(Colors.AliceBlue);
}
...and still see the Flyout
: ...并且仍然看到
Flyout
:
You may also handle the Opened
, Opening
, Closed
or Closing
events of the MenuFlyout
.您还可以处理
MenuFlyout
的Opened
、 Opening
、 Closed
或Closing
事件。
Or use an AttachedFlyout
and show it programmatically using the ShowAttachedFlyout
method:或者使用
AttachedFlyout
并使用ShowAttachedFlyout
方法以编程方式显示它:
private void Button_Click(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
//...
Flyout.ShowAttachedFlyout(button);
}
XAML: XAML:
<Button Content="Button With Flyout" Click="Button_Click">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Edit" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
</Button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.