1

I am trying to animate the location of a MapIcon in the UWP version of Bing Maps. I am having problems specifying the PropertyPath for the Latitude component (a double value) of the GeoPoint used as the center value for the icon:

        MapIcon mapIcon1 = new MapIcon();
        mapIcon1.Location = myMap.Center;
        mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
        mapIcon1.Title = "My Friend";
        mapIcon1.Image = mapIconStreamReference;
        mapIcon1.ZIndex = 0;
        myMap.MapElements.Add(mapIcon1);

        double centerLatitude = myMap.Center.Position.Latitude;
        double centerLongitude = myMap.Center.Position.Longitude;
        Storyboard storyboard = new Storyboard();
        DoubleAnimation animation = new DoubleAnimation();
        animation.From = centerLatitude;
        animation.To = centerLatitude + 100f;
        animation.Duration = new Duration(new TimeSpan(0, 0, 0, 5));
        animation.EnableDependentAnimation = true;
        storyboard.Children.Add(animation);
        //Storyboard.SetTargetProperty(animation, "(MapIcon.Location)(Geopoint.Position)(BasicGeoposition.Latitude)");
        //Storyboard.SetTargetProperty(animation, "(MapIcon.Location)(MapControl.Center)(Geopoint.Position)(BasicGeoposition.Latitude)");
        //Storyboard.SetTargetProperty(animation, "(MapIcon.Location)(BasicGeoposition.Latitude)");
        //Storyboard.SetTargetProperty(animation, "(MapIcon.Location.Latitude)");
        Storyboard.SetTarget(storyboard, mapIcon1);
        storyboard.Begin();

None of the commented out statements work; they all result in the "Cannot resolve TargetProperty on specified object" error. I was particularly hopeful for the first attempt "(MapIcon.Location)(Geopoint.Position)(BasicGeoposition.Latitude)", but no luck.

(I am able to animate the Color attribute of a MapIcon successfully.)

Duncan Lawler
  • 1,772
  • 8
  • 13
Sabuncu
  • 5,095
  • 5
  • 55
  • 89
  • Hi! Did you find any working solution? Would you mind to share with us, please? – NoWar Jun 11 '21 at 06:48
  • 1
    @DmitryBoyko As indicated in the answer below, this was not possible at the time, and I gave up and moved on. Not sure if it's changed since then. Thanks. – Sabuncu Jun 11 '21 at 08:46

1 Answers1

2

Storyboard.SetTargetProperty targets the dependency property where the animation applies. So, what you want to apply animation to 'Latitude'is impossible.

You would have to make it by yourself. For example, using the DispatcherTimer.

Xie Steven
  • 8,544
  • 1
  • 9
  • 23
  • Thanks. Just to be clear, are you saying that Latitude is not a dependency property? Documentation says `LocationProperty` is a dependency property. Thanks. – Sabuncu Feb 06 '19 at 21:12
  • `BasicGeoposition` is struct. – Xie Steven Feb 07 '19 at 01:51
  • Would you mind to suggest concrete approach to animate a MapIcon, please? SHoul dwe just update Location property periodically so we see smoothing movement? – NoWar Jun 11 '21 at 06:47