Windows Phone 8中缺少ButtonBase.Click

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows Phone 8中缺少ButtonBase.Click相关的知识,希望对你有一定的参考价值。

我有mainPage.xaml,里面有一个网格,在网格里面我有一个画布。

<Grid Loaded="Grid_Loaded" ButtonBase.Click="Grid_ButtonClick">
    <Canvas x:Name="GameCanvas" Margin="12,52,98,26" />
</Grid>

我有一些用户控件UC1,UC2,UC3等,根据游戏级别生成许多按钮。我使用MainPage.xaml.cs中的列表值填充按钮的内容

private List<int> _listofValues = new List<int>();

因为所有按钮的功能都相同,所以我想在网格或画布中处理父控件中的按钮单击。

我可以在普通的WPF应用程序中这样做。第一个代码ButtonBase.Click="Grid_ButtonClick"但我不能在Windows Phone 8应用程序中这样做。它给出了编译时错误。

不知道如何在Windows手机中实现buttonBase.click事件?

答案

没有父UI元素处理按钮单击,您可以使用GestureService

这使您可以在动态创建按钮时完全控制按钮。在Geasture Listener事件中,您可以根据发件人处理每个事件。

var gl = GestureService.GetGestureListener(your_newButton);

gl.Tap += new EventHandler<GestureEventArgs>(GestureListener_Tap);

然后,当您注册它们或完成它们之后,您可以在这里处理它们。

private void GestureListener_Tap(object sender, GestureEventArgs e)
{
    Button theSendingButton = (sender as Button);
    //Handle your ish here
}

参考和完整的例子here

以上是关于Windows Phone 8中缺少ButtonBase.Click的主要内容,如果未能解决你的问题,请参考以下文章

为什么Windows Phone 8模拟器不能在Windows 8.1中运行?

MapControl为空? Windows Phone 8

如何以编程方式检测Windows Phone 8.1操作系统版本?

Windows Phone 8 Geolocator 无法设置desiredAccuracy = High 并且绑定到 PositionChanged 事件

在 windows phone 8 和 windows 8 中使用 Google Play 游戏服务

为啥 Windows Phone 8 模拟器不能在 Windows 8.1 中运行?