带有图像的 WP7 Bing 地图图钉模板不显示

发布于 2024-10-11 05:16:17 字数 730 浏览 4 评论 0原文

我的最终目标是在 WP7 应用程序的 Bing 地图上添加带有自定义图像的图钉。我创建了一个控件模板和一个带有图钉的地图。现在,我可以显示默认图钉,但当我尝试对其进行模板化时,没有任何显示。这就是我现在所拥有的:

<phone:PhoneApplicationPage.Resources>
    <ControlTemplate x:Key="PushpinControlTemplate" TargetType="my:Pushpin">
        <Image Source="/Images/Pins/pin.png" />
    </ControlTemplate>
</phone:PhoneApplicationPage.Resources>

<my:Map Name="mapMain" CredentialsProvider="CredKey">
    <my:Pushpin/>
</my:Map>

如果我应用 PushpinControl 模板,则不会显示任何内容:

<my:Pushpin Template="{StaticResource BoaPushpinControlTemplate}" />

如果我删除模板,它会显示默认的黑色形状。

我的模板一定是错误的,但我不知道问题出在哪里。我可以在 ControlTemplate 中没有图像吗?

My ultimate goal is to have pushpins with custom images on a Bing Map in a WP7 app. I have created a control template and a map with a pushpin. Right now, I can get the default pushpins to show up, but nothing shows when I try to template it. Here's what I have right now:

<phone:PhoneApplicationPage.Resources>
    <ControlTemplate x:Key="PushpinControlTemplate" TargetType="my:Pushpin">
        <Image Source="/Images/Pins/pin.png" />
    </ControlTemplate>
</phone:PhoneApplicationPage.Resources>

<my:Map Name="mapMain" CredentialsProvider="CredKey">
    <my:Pushpin/>
</my:Map>

If I apply the PushpinControl template nothing shows up:

<my:Pushpin Template="{StaticResource BoaPushpinControlTemplate}" />

If I remove the template, it shows the default black shape.

I must be doing my template incorrectly, but I don't know what the problem is. Can I not have an image in the ControlTemplate?

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

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

发布评论

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

评论(2

瀟灑尐姊 2024-10-18 05:16:17

如果您没有在地图上使用 ItemSource 绑定,则使用简单的内容控制方法

   <maps:Pushpin Location="{Binding Location}">
            <Image Source="/Images/Pins/pin.png"   />
   </maps:Pushpin>

或者如果您动态填充图钉,请使用以下方法

 <maps:Map x:Name="map" >
    <maps:MapItemsControl ItemsSource="{Binding Collection}">
        <maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <maps:Pushpin Location="{Binding Location}">
                    <Image Source="/Images/Pins/pin.png"   />
                </maps:Pushpin>
            </DataTemplate>
        </maps:MapItemsControl.ItemTemplate>
    </maps:MapItemsControl>
</maps:Map>

If you arent using ItemSource binding on the Map then use simple content control approach

   <maps:Pushpin Location="{Binding Location}">
            <Image Source="/Images/Pins/pin.png"   />
   </maps:Pushpin>

Or if you dynamically populating the push-pins use the below approach

 <maps:Map x:Name="map" >
    <maps:MapItemsControl ItemsSource="{Binding Collection}">
        <maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <maps:Pushpin Location="{Binding Location}">
                    <Image Source="/Images/Pins/pin.png"   />
                </maps:Pushpin>
            </DataTemplate>
        </maps:MapItemsControl.ItemTemplate>
    </maps:MapItemsControl>
</maps:Map>
挖个坑埋了你 2024-10-18 05:16:17

尽管这个帖子有点旧,我还是要发布我的建议:

尝试这个链接 使用图钉,它对我有用(创建新样式并在图钉声明中使用它)

(App.xaml,不要忘记命名空间! )

xmlns:m="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps" >

<Application.Resources>    
    <Style TargetType="m:Pushpin" x:Key="PushpinStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="m:Pushpin">
                    <Image Width="24" Height="24" Source="path_to_pic" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

(在 xaml 中有地图)

<Grid x:Name="LayoutRoot" Background="Transparent">
    <m:Map x:Name="Map" Mode="Aerial"
              CredentialsProvider="CredKey">
        <m:MapItemsControl x:Name="Content">
            <m:MapItemsControl.ItemTemplate>
                <DataTemplate>
                    <m:Pushpin Location="{Binding Location}" Style="{StaticResource PushpinStyle}" />
                </DataTemplate>
            </m:MapItemsControl.ItemTemplate>
        </m:MapItemsControl>
    </m:Map>
</Grid>

如果这不起作用,请检查图片的构建操作是否设置为内容。

我花了一段时间才弄清楚这一点,所以我希望我可以帮助别人,尽管这个线程已经很旧了。 ;)

Even though this thread is a little bit old I'm going to post my suggestion:

Try out this link Working with Pushpins, it is working for me (create a new style and use it in pushpin declaration)

(App.xaml, do not forget the namespace!)

xmlns:m="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps" >

<Application.Resources>    
    <Style TargetType="m:Pushpin" x:Key="PushpinStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="m:Pushpin">
                    <Image Width="24" Height="24" Source="path_to_pic" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

(in the xaml there the map is)

<Grid x:Name="LayoutRoot" Background="Transparent">
    <m:Map x:Name="Map" Mode="Aerial"
              CredentialsProvider="CredKey">
        <m:MapItemsControl x:Name="Content">
            <m:MapItemsControl.ItemTemplate>
                <DataTemplate>
                    <m:Pushpin Location="{Binding Location}" Style="{StaticResource PushpinStyle}" />
                </DataTemplate>
            </m:MapItemsControl.ItemTemplate>
        </m:MapItemsControl>
    </m:Map>
</Grid>

If this isn't working check if the Build Action of your picture is set to content.

Took me a while to figure this out, so i hope i could help someone, despite the fact that this thread is old. ;)

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