0

UWP で Xamarin Map のカスタム レンダラーを作成しようとしていますが、PCL のコレクション変更イベントが UWP カスタム レンダラーで適切なイベントをトリガーしていません。iOS と Android で問題なく動作します。

次のコードでは、OnItemsSourcePropertyChanged が 5 秒ごとに呼び出されていても、CustomMapRenderer で ItemsCollectionChanged イベントが呼び出されることはありません。

   public class CustomMap : Map
   { 

    #region << Events >>

    public event EventHandler ItemsCollectionChanged;

    #endregion

          private static void OnItemsSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
          {
                 var map = bindable as CustomMap;

                 if (map == null)
                       return;

                 map.ItemsSource.CollectionChanged += (s, e) =>
                 {
                       SetPin(bindable);
                       if (map.ItemsCollectionChanged != null)
                       {
                              map.ItemsCollectionChanged(bindable, new EventArgs());
                       }
                 }; 
          }

   }

  [assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
 Namespace MyNamespace.Renderers
{
  public class CustomMapRenderer : MapRenderer
 {
    MapControl _nativeMap;


    protected override void OnElementChanged(ElementChangedEventArgs<Map> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null)
        {
            _nativeMap.MapElementClick -= OnMapElementClick;
            _nativeMap.Children.Clear();
            _nativeMap = null;
        }

        if (e.NewElement != null)
        {
            var formsMap = (CustomMap)e.NewElement;
            formsMap.ItemsCollectionChanged += ItemsCollectionChanged;

            _pinClickedCommand = formsMap.PinClickedCommand;
            _routeCoordinates = formsMap.ItemsSource;
            _nativeMap = Control as MapControl;
            _nativeMap.Children.Clear();
            _nativeMap.MapElementClick += OnMapElementClick;
            var snPosition = new BasicGeoposition { Latitude = 45, Longitude = -88 };
            Geopoint snPoint = new Geopoint(snPosition);

            var mapIcon = new MapIcon();
            if (mapIcon != null)
            {
                _nativeMap.MapElements.Remove(mapIcon);
            }

            mapIcon.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
            mapIcon.Location = snPoint;
            mapIcon.NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1.0);
            _nativeMap.MapElements.Add(mapIcon);
            _nativeMap.Center = snPoint;
        }

    }


    void ItemsCollectionChanged(object sender, EventArgs e)
    {
       ;
    }
  }
 }
4

1 に答える 1