如何通过点击bing地图中的图钉来获取图钉的模型对象?

发布于 2024-12-28 15:33:31 字数 948 浏览 1 评论 0原文

我的图钉以如下常见方式添加到地图中:

C#:

private readonly ObservableCollection<PushpinModel> _pushpins = new observableCollection<PushpinModel>();

public ObservableCollection<PushpinModel> Pushpins
{
    get{return _pushpins;}
}

XAML:

<my:MapItemsControl ItemsSource="{Binding Pushpins}">
    <my:MapItemsControl.ItemTemplate>
        <DataTemplate>
            <my:Pushpin Style="{StaticResource PushpinStyle}" 
                        MouseLeftButtonUp="Pushpin_MouseLeftButtonUp" 
                        Location="{Binding Location}" 
                        Content="{Binding Num}">
            </my:Pushpin>
        </DataTemplate>
    </my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>

单击图钉时,我可以将图钉作为发送者并获取位置信息。 但我想追踪它的 PushpinModel 对象以获取与 Pushpin 相关的其他信息,例如名称、描述、网址等。我该怎么做?

My pushpins are added to the map in a common way like this:

C#:

private readonly ObservableCollection<PushpinModel> _pushpins = new observableCollection<PushpinModel>();

public ObservableCollection<PushpinModel> Pushpins
{
    get{return _pushpins;}
}

XAML:

<my:MapItemsControl ItemsSource="{Binding Pushpins}">
    <my:MapItemsControl.ItemTemplate>
        <DataTemplate>
            <my:Pushpin Style="{StaticResource PushpinStyle}" 
                        MouseLeftButtonUp="Pushpin_MouseLeftButtonUp" 
                        Location="{Binding Location}" 
                        Content="{Binding Num}">
            </my:Pushpin>
        </DataTemplate>
    </my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>

On clicking a pushpin i can get the Pushpin as sender and get Location information.
But i would like to track down to it's PushpinModel object to get other informations associated with the Pushpin, like name, description, urls, etc. How can i do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠佳期 2025-01-04 15:33:31

首先,您应该使用 Tap 事件,而不是 MouseLeftButtonUp

其次,事件处理程序中的 senderPushpin,它的 DataContext 属性是您绑定的 PushpinModel,所以简单地做:

var pushpinModel = (sender as Pushpin).DataContext as PushpinModel;

First of all, you should use the Tap event, instead of MouseLeftButtonUp.

Secondly, the sender in the event handler, is the Pushpin, and it's DataContext property is your bound PushpinModel, so simply do:

var pushpinModel = (sender as Pushpin).DataContext as PushpinModel;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文