2

我的最终目标是在 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 中没有图像吗?

4

2 回答 2

1

如果您没有在 Map 上使用 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>
于 2011-01-11T02:28:45.857 回答
1

尽管这个帖子有点老了,但我还是要发表我的建议:

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

(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>

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

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

于 2011-11-21T14:28:44.227 回答