【发布时间】:2017-02-04 20:07:29
【问题描述】:
我正在使用 Windows Presentation Foundation (WPF) 制作 GUI。当我鼠标单击一个按钮(左或右)时,我想要显示一个消息框。到目前为止,我已经设法从教程中制作了一个示例,但它仅在我右键单击时有效,而在我左键单击时无效按钮。我在我的代码中看不到任何东西,这应该会阻止左键单击,所以我希望你能帮助我。
XAML 代码
<Grid>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="72">
Hello, WPF!
</TextBlock>
<!-- This button shuld activate the even MyButton_MouseUp -->
<Button Margin="200,250,200,20" Name="MyButton" MouseUp="MyButton_MouseUp">
Test
</Button>
</Grid>
C# 代码
// This only works on right-click
private void MyButton_MouseUp(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Hello world!");
}
【问题讨论】: