SuperMap.WindowsPhone.Mapping.Map.OnLayersPropertyChanged C# (CSharp) Method

OnLayersPropertyChanged() private static method

private static OnLayersPropertyChanged ( DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e ) : void
d System.Windows.DependencyObject
e System.Windows.DependencyPropertyChangedEventArgs
return void
        private static void OnLayersPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Map map = d as Map;
            LayerCollection newValue = e.NewValue as LayerCollection;
            LayerCollection oldValue = e.OldValue as LayerCollection;
            if (oldValue != null)
            {
                oldValue.Progress -= new EventHandler<ProgressEventArgs>(map.layersProgressHandler);
                oldValue.LayersInitialized -= new EventHandler(map.Layers_LayersInitialized);
                oldValue.CollectionChanged -= new NotifyCollectionChangedEventHandler(map.Layers_CollectionChanged);
                foreach (Layer layer in oldValue)
                {
                    map.RemoveMapLayers(layer);
                }
                map.ResetMapStatus();
            }
            if (newValue != null)
            {
                newValue.Progress += new EventHandler<ProgressEventArgs>(map.layersProgressHandler);
                newValue.LayersInitialized += new EventHandler(map.Layers_LayersInitialized);
                newValue.CollectionChanged += new NotifyCollectionChangedEventHandler(map.Layers_CollectionChanged);
                foreach (Layer layer2 in newValue)
                {
                    Map map2 = layer2.GetValue(MapProperty) as Map;
                    if ((map2 != null) && (map2 != map))
                    {
                        throw new ArgumentException(ExceptionStrings.LayerToMap);
                    }
                    layer2.SetValue(MapProperty, map);
                    layer2.LayerChanged += new Layer.LayerChangedHandler(map.layer_OnLayerChanged);
                    layer2.Initialized += new EventHandler<EventArgs>(map.layer_Initialized);//如何使用非静态方法
                    if (!layer2.IsInitialized && (map.panHelper != null))
                    {
                        layer2.Initialize();
                    }
                }
            }
            map.raisePropertyChanged("Layers");
        }