use*_*635 5 c# xaml bing-maps pushpin windows-8
我正在使用C#和XAML开发Windows 8应用程序.该应用程序有一个地图页面,其中包含自定义图钉.我使用以下代码添加了自定义图钉:
<Style x:Key="PushPinStyle" TargetType="bm:Pushpin">
<Setter Property="Width" Value="25"/>
<Setter Property="Height" Value="39"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Image Source="Assets/pushpin_icon.png" Stretch="Uniform" HorizontalAlignment="Left"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
启用上述代码后,除非用户移动地图,否则图钉不会显示.以下代码用于生成地图.DataTemplate-
<DataTemplate x:Key="pushpinSelector" >
<bm:Pushpin Tapped="pushpinTapped" Style="{StaticResource PushPinStyle}">
<bm:MapLayer.Position >
<bm:Location Latitude="{Binding Latitude}" Longitude="{Binding Longitude}"/>
</bm:MapLayer.Position>
</bm:Pushpin>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
地图XAML-
<bm:Map.Children>
<bm:MapItemsControl Name="pushPinModelsLayer"
ItemsSource="{Binding Results}"
ItemTemplate="{StaticResource pushpinSelector}" />
</bm:Map.Children>
</bm:Map>
Run Code Online (Sandbox Code Playgroud)
删除图钉的自定义样式后,默认图钉会正确显示而无需移动地图.我希望cutom图钉能够同样显示,而无需手动移动地图.感谢提前解决方案.
您是否尝试过使用地图图钉的自定义控件
使用提供的用户控件模板创建控件,添加必要的组件、事件,进行您需要的自定义。
例子 :
CustomPushPin pushpin = new CustomPushPin();
mapView.Children.Add(pushPin);
MapLayer.SetPosition(pushPin, location);
在哪里 ,
如果您仍然遇到此问题,请告诉我