0

我正在开发一个 Windows 商店应用程序。在我的应用程序中,我想在运行时为 pushpin.tapped 事件创建一个图钉和一个方法。我的目标是将变量传递给 puhpin_Tapped 方法并通过消息对话框显示该变量的值。这是我的代码:

    Pushpin pushpin = new Pushpin();
    pushpin.Background = new SolidColorBrush(Colors.Blue);
    MapLayer.SetPosition(pushpin, loc);
    pushpin.Name = sd.name;
    pushpin.Tapped +=pushpin_Tapped(pushpin.Name);
    map.Children.Add(pushpin);

这是我的 pushpin_Tapped 方法:

    private async void pushpin_Tapped(string _name)
    {
        MessageDialog myMessage = new MessageDialog(_name);
        await myMessage.ShowAsync();
    }

但是,当我编写这些代码块时,会出现错误,因为“无法将类型 'void' 隐式转换为 'Windows.UI.Xaml.Input.TappedEventHandler'” 在“pushpin_Tapped(pushpin.Name)”下方绘制一条红线。

那么我做错了什么?谢谢...

4

2 回答 2

0

尝试这个。

private async void pushpin_Tapped(object sender, TappedRoutedEventArgs e)
{
    MessageDialog myMessage = new MessageDialog(((Pushpin)sender).Name);
    await myMessage.ShowAsync();
}
于 2013-10-01T07:17:10.580 回答
0
private async void pushpin_Tapped(object sender, TappedRoutedEventArgs e)
     {
        MessageDialog myMessage = new MessageDialog(pushpin.Name);
        await myMessage.ShowAsync();
     }
于 2013-10-01T06:58:47.757 回答