private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { MapProgressBar mp = d as MapProgressBar; Map oldMap = e.OldValue as Map; Map newMap = e.NewValue as Map; if (oldMap != null) { oldMap.Progress -= mp.map_Progress; } if (newMap != null) { newMap.Progress += mp.map_Progress; } }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or /// internal processes (such as a rebuilding layout pass) call /// <see cref="M:System.Windows.Controls.Control.ApplyTemplate"/>. /// </summary> public override void OnApplyTemplate() { navControl = this; base.OnApplyTemplate(); ResetRotationGrid = GetTemplateChild("ResetRotationGrid") as FrameworkElement; projection = GetTemplateChild("NavProjection") as PlaneProjection; SlantSlider = GetTemplateChild("SlantSlider") as Slider; SlantSliderGrid = GetTemplateChild("SlantSliderGrid") as FrameworkElement; NavCircle = GetTemplateChild("NavCircle") as Border; NavCircleScale = GetTemplateChild("NavCircleScale") as ScaleTransform; ZoomGrid = GetTemplateChild("ZoomGrid_") as FrameworkElement; ZoomGridOuterBorder = GetTemplateChild("ZoomGridBorder1") as Border; ZoomGridInnerBorder = GetTemplateChild("ZoomGridBorder2") as Border; SlantText = GetTemplateChild("SlantText_") as TextBlock; SlantGlass = GetTemplateChild("GlobeGlass") as FrameworkElement; //ZoomLevelStack = GetTemplateChild("ZoomLevelStack") as StackPanel; ZoomGridStack = GetTemplateChild("ZoomGridStack") as StackPanel; BottomZoomWingUpDownExpand = GetTemplateChild("BottomZoomWingUpDownExpand") as UpDownExpand; TopZoomWingUpDownExpand = GetTemplateChild("TopZoomWingUpDownExpand") as UpDownExpand; BottomZoomCollapseButton = GetTemplateChild("BottomZoomWingCollapseButton") as Button; TopZoomCollapseButton = GetTemplateChild("TopZoomWingCollapseButton") as Button; ExpandZoomBar = GetTemplateChild("ExpandZoomBar") as Storyboard; ShrinkZoomBar = GetTemplateChild("ShrinkZoomBar") as Storyboard; ExpandProgressBarSpacer = GetTemplateChild("ExpandProgressBarSpacer") as Storyboard; ShrinkProgressBarSpacer = GetTemplateChild("ShrinkProgressBarSpacer") as Storyboard; ProgressBarSpacer = GetTemplateChild("ProgressBarSpacer") as FrameworkElement; NavProjection = GetTemplateChild("NavProjection") as PlaneProjection; ScaleBarBlock = GetTemplateChild("ScaleBarBlock") as FrameworkElement; PaddingLeftForScaleBarTextMeters = GetTemplateChild("PaddingLeftForScaleBarTextMeters") as FrameworkElement; PaddingLeftTopNotch = GetTemplateChild("PaddingLeftTopNotch") as FrameworkElement; PaddingLeftForScaleBarTextMiles = GetTemplateChild("PaddingLeftForScaleBarTextMiles") as FrameworkElement; PaddingLeftBottomNotch = GetTemplateChild("PaddingLeftBottomNotch") as FrameworkElement; ScaleBarTextForMeters = GetTemplateChild("ScaleBarTextForMeters") as TextBlock; ScaleBarTextForMiles = GetTemplateChild("ScaleBarTextForMiles") as TextBlock; ScaleBar = GetTemplateChild("scaleBar") as FrameworkElement; root = GetTemplateChild("root") as FrameworkElement; NavOpacitySliderGrid = GetTemplateChild("NavOpacitySliderGrid") as FrameworkElement; NavOpacitySlider = GetTemplateChild("NavOpacitySlider") as Slider; OpacityText = GetTemplateChild("OpacityText") as FrameworkElement; progressBarGrid = GetTemplateChild("progressBarGrid") as FrameworkElement; ScaleBarInnerBorder = GetTemplateChild("ScaleBarInnerBorder") as Border; ScaleBarWingCollapseButton = GetTemplateChild("ScaleBarWingCollapseButton") as Button; ScaleBarWingCollapseImage = GetTemplateChild("ScaleBarWingCollapseImage") as Image; ScaleBarOuterBorder = GetTemplateChild("ScaleBarOuterBorder") as Border; progressBar = GetTemplateChild("progressBar") as MapProgressBar; ScaleBarWingLeftRightExpand = GetTemplateChild("ScaleBarWingLeftRightExpand") as LeftRightExpand; if (ExpandProgressBarSpacer != null) ExpandProgressBarSpacer.Completed += expandprogressbarSpacer_Completed; if (ExpandZoomBar != null) ExpandZoomBar.Completed += ExpandZoomBar_Completed; if (ShrinkZoomBar != null) ShrinkZoomBar.Completed += ShrinkZoomBar_Completed; if (ScaleBarWingCollapseButton != null) ScaleBarWingCollapseButton.Click += ScaleBarWingCollapseButton_Click; if (BottomZoomCollapseButton != null) BottomZoomCollapseButton.Click += ZoomWingCollapseButton_Click; if (TopZoomCollapseButton != null) TopZoomCollapseButton.Click += ZoomWingCollapseButton_Click; if (SlantGlass != null) SlantGlass.MouseLeftButtonDown += GlobeGlass_MouseLeftButtonDown; if (SlantSlider != null) SlantSlider.ValueChanged += SlantSlider_ValueChanged; if (NavOpacitySlider != null) NavOpacitySlider.ValueChanged += NavOpacitySlider_ValueChanged; ResourceDictionary rd = root.Resources; // try local resources first for zoom level brushes levelGreaterThanBrush = rd["levelGreaterThanBrush"] as SolidColorBrush; levelLessThanBrush = rd["levelLessThanBrush"] as SolidColorBrush; levelEqualsBrush = rd["levelEqualsBrush"] as SolidColorBrush; if (levelGreaterThanBrush == null) { // if local resources not used, try the application global resources rd = Application.Current.Resources; levelGreaterThanBrush = rd["levelGreaterThanBrush"] as SolidColorBrush; levelLessThanBrush = rd["levelLessThanBrush"] as SolidColorBrush; levelEqualsBrush = rd["levelEqualsBrush"] as SolidColorBrush; } VerticalAlignment va = this.VerticalAlignment; if (va == VerticalAlignment.Bottom) { bottomAligned = true; ScaleBarOuterBorder.CornerRadius = new CornerRadius(0, 21, 0, 0); ScaleBarOuterBorder.VerticalAlignment = VerticalAlignment.Bottom; ScaleBarInnerBorder.CornerRadius = new CornerRadius(0, 20, 0, 0); OpacityText.VerticalAlignment = VerticalAlignment.Bottom; NavOpacitySliderGrid.VerticalAlignment = VerticalAlignment.Bottom; ZoomGridOuterBorder.CornerRadius = new CornerRadius(0, 21, 0, 0); ZoomGridInnerBorder.CornerRadius = new CornerRadius(0, 20, 0, 0); ZoomGrid.VerticalAlignment = VerticalAlignment.Bottom; ZoomGridOuterBorder.VerticalAlignment = VerticalAlignment.Top; ZoomGridInnerBorder.Padding = new Thickness(5, 5, 5, 110); NavCircle.VerticalAlignment = VerticalAlignment.Bottom; NavCircle.RenderTransformOrigin = new Point(0, 1); SlantSliderGrid.Margin = new Thickness(85, 0, 0, 6); SlantSliderGrid.VerticalAlignment = VerticalAlignment.Bottom; SlantText.VerticalAlignment = VerticalAlignment.Bottom; ResetRotationGrid.VerticalAlignment = VerticalAlignment.Bottom; BottomZoomCollapseButton.Visibility = Visibility.Collapsed; TopZoomCollapseButton.Visibility = Visibility.Visible; } string strvalue = Application.Current.Resources["UsePlaneProjection"] as string; if (strvalue != null) usePlaneProjection = bool.Parse(strvalue); if (mapAngle != 0 && usePlaneProjection) SlantSlider.Value = mapAngle; if (this.Map != null) { Map.ExtentChanged += new EventHandler<ExtentEventArgs>(Map_ExtentChanged); Map.Progress += projectionCheck; Map.Progress += progressBarCheck; } }