3
        <maps:Map x:Name="map">
            <maptk:MapExtensions.Children>
                <maptk:MapItemsControl Name="pushpinItems">
                    <maptk:MapItemsControl.ItemTemplate>
                        <DataTemplate>
                            <maptk:Pushpin GeoCoordinate="{Binding geoCoordinateLocation}" Content="{Binding name}" PositionOrigin="0.5,0.5"/>
                        </DataTemplate>
                    </maptk:MapItemsControl.ItemTemplate>
                </maptk:MapItemsControl>
            </maptk:MapExtensions.Children>
        </maps:Map> 

    ...

    ObservableCollection<PinItem> pinsCollection = new ObservableCollection<PinItem>();


    private async void updateMap()
    {

        WebApiWorker webApi = new WebApiWorker();
        var responce = await webApi.GetAllPins();

        this.pinsCollection.Clear();

        foreach (PinItem pin in responce.array)
        {
            this.pinsCollection.Add(busActivity.MonitoredVehicleJourney);

        }

    }

我每 5 秒调用一次 updateMap() 方法,以从 Web 服务获取更新的 pin 位置。当图钉更新时,它们会在屏幕上跳跃 5 毫米。

如果我设置图钉 PositionOrigin="0,0" 则图钉不再跳跃/闪烁,但它们很少被筛选,因为我有椭圆图钉。

任何想法如何解决这一问题?

4

2 回答 2

1

我用自定义ControlTemplate来解决这个问题:

<ControlTemplate TargetType="toolkit:Pushpin" x:Key="PinTemplate">
    <Grid x:Name="ContentGrid" FlowDirection="LeftToRight" Margin="0,-60,0,0">
        <StackPanel Orientation="Vertical">
            <Grid Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" 
                    HorizontalAlignment="Left" 
                    MinHeight="31" 
                    MinWidth="29">
                <ContentPresenter x:Name="Presenter"
                    Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"
                    FlowDirection="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FlowDirection}" 
                    Margin="4" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </Grid>
            <Polygon Fill="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" 
                Points="0,0 29,0 0,29" 
                Width="29" 
                Height="29" 
                Margin="0,-1,0,0"
                HorizontalAlignment="Left"/>
        </StackPanel>
    </Grid>
</ControlTemplate>

然后我从我的代码中创建了图钉,如下所示:

var pp = new Pushpin
{
    Background = cObject.Bcolor,
    GeoCoordinate = cObject.Coordinate,
    Content = ppIc.Convert(cObject.Name, typeof (BitmapImage), null, CultureInfo.CurrentUICulture),
    DataContext = cObject,
    Template = this.Resources["PinTemplate"] as ControlTemplate
};
pp.Tap += UIElement_OnTap;

var overlay = new MapOverlay
{
    Content = pp,
    GeoCoordinate = pp.GeoCoordinate
};
_pushpinLayer.Add(overlay);

这里的关键是在图钉模板的根级别上设置适当的边距,Grid以便它将所有元素移动到更高的位置,而您不必设置PositionOrigin="0,1".

于 2014-04-05T15:34:31.973 回答
0

我在 3d 派对网站上找到了一些解决方法:

我找到了解决方法。在我清除 PushPin-Collection(导致那些跳跃的 PushPins)之前,我创建了地图的位图并将其显示在地图上方。更新集合后,我再次隐藏位图。这适用于 Moment,但需要的资源比必要的多:

System.Windows.Media.Imaging.WriteableBitmap bmp = new System.Windows.Media.Imaging.WriteableBitmap((int)_map.ActualWidth,(int)_map.ActualHeight);
    bmp.Render(_map, new System.Windows.Media.TranslateTransform());
    bmp.Invalidate();
    MapImage = bmp;
    MapImageVisibility = Visibility.Visible;

但它看起来不够好:(

于 2013-12-11T07:43:39.347 回答