Example #1
0
        /// <summary>
        /// Add the given map layer to this expandable stack panel.
        /// </summary>
        /// <param name="Layer">A map layer.</param>
        /// <param name="Visibility">The map layer is visible or not at the start of the application.</param>
        public void AddLayer(IMapLayer Layer, Visibility Visibility = Visibility.Visible)
        {
            #region Initial checks

            if (Layer == null)
                throw new ApplicationException("The parameter 'Layer' must not be null!");

            var CurrentLayerAsCanvas = Layer as Canvas;

            if (CurrentLayerAsCanvas == null)
                throw new ApplicationException("The parameter 'Layer' must inherit from Canvas!");

            if (Layer.Id == null)
                throw new ApplicationException("The identification of the 'Layer' must be set!");

            if (Layer.MapControl == null)
                throw new ApplicationException("The MapControl of the 'Layer' must be set!");

            #endregion

            var Checkbox = new CheckBox();
            Checkbox.Content   = Layer.Id;
            Checkbox.IsChecked = Visibility == Visibility.Visible;
            Layer.Visibility   = Visibility;

            #region Register Checkbox.MouseEnter event

            Checkbox.MouseEnter += (o, e) =>
                {
                    var _CheckBox = o as CheckBox;
                    _CheckBox.Foreground = new SolidColorBrush(Color.FromArgb(255, 200, 200, 200));
                    _CheckBox.Background = new SolidColorBrush(Colors.White);
                };

            #endregion

            #region Register Checkbox.MouseLeave event

            Checkbox.MouseLeave += (o, e) =>
                {
                    var _CheckBox = o as CheckBox;
                    _CheckBox.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    _CheckBox.Background = new SolidColorBrush(Colors.Gray);
                };

            #endregion

            #region Register Checkbox.Click event

            Checkbox.Click += (o, e) =>
                {

                    var _CheckBox = o as CheckBox;

                    if (_CheckBox.IsChecked.Value)
                        CurrentLayerAsCanvas.Animate(Property:     "Opacity",
                                                     From:         0.0,
                                                     To:           1.0,
                                                     Milliseconds: AnimationSpeed,
                                                     StartAction:  (UIElement) => {
                                                         Layer.Redraw();
                                                         UIElement.Visibility = Visibility.Visible;
                                                     });

                    else
                        CurrentLayerAsCanvas.Animate(Property:     "Opacity",
                                                     From:         1.0,
                                                     To:           0.0,
                                                     Milliseconds: AnimationSpeed,
                                                     FinalAction:  (UIElement) => UIElement.Visibility = Visibility.Hidden);

                };

            #endregion

            base.AddUIElement(Checkbox);
        }