Esempio n. 1
0
 public static void RemoveAdorners(this AdornerLayer layer, UIElement element)
 {
     foreach (Adorner remove in layer?.GetAdorners(element) ?? new Adorner[0])
     {
         layer.Remove(remove);
     }
 }
Esempio n. 2
0
        private static void RemoveAdorner(Slider slider)
        {
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(slider);
            Adorner      adorner      = adornerLayer?.GetAdorners(slider)?.FirstOrDefault(x => x is SliderValueAdorner);

            if (adorner != null)
            {
                adornerLayer.Remove(adorner);
                (adorner as SliderValueAdorner)?.Cleanup();
            }
        }
Esempio n. 3
0
        private static void SetWatermarkVisibility(Control control, bool visibility)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            if (visibility)
            {
                layer?.Add(new WatermarkAdorner(control, GetWatermark(control)));
            }
            else
            {
                layer
                ?.GetAdorners(control)
                ?.OfType <WatermarkAdorner>()
                .ForEach(adorner =>
                {
                    adorner.Hide(true);
                    layer.Remove(adorner);
                });
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="uiElement"></param>
        /// <returns></returns>
        public static Adorner GetAdorner(this UIElement uiElement)
        {
            Adorner result = null;

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(uiElement);

            Adorner[] adorners = adornerLayer?.GetAdorners(uiElement);
            if (adorners != null)
            {
                foreach (var adorner in adorners)
                {
                    if (adorner is UIElementOverlayAdorner)
                    {
                        result = adorner;
                        break;
                    }
                }
            }

            return(result);
        }
Esempio n. 5
0
        private static void RemoveWatermark(UIElement control)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            Adorner[] adorners = layer?.GetAdorners(control);
            if (adorners == null)
            {
                return;
            }

            foreach (var adorner in adorners)
            {
                if (!(adorner is WatermarkAdorner))
                {
                    continue;
                }

                adorner.Visibility = Visibility.Hidden;
                layer.Remove(adorner);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Remove the watermark from the specified element
        /// </summary>
        /// <param name="control">Element to remove the watermark from</param>
        private static void RemoveWatermark(UIElement control)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            // layer could be null if control is no longer in the visual tree

            Adorner[] adorners = layer?.GetAdorners(control);
            if (adorners == null)
            {
                return;
            }

            foreach (Adorner adorner in adorners)
            {
                if (!(adorner is WatermarkAdorner))
                {
                    continue;
                }

                adorner.Visibility = Visibility.Hidden;
                layer.Remove(adorner);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 添加并获取对应类型的装饰器
        /// </summary>
        /// <param name="uIElement">需要添加装饰器的控件</param>
        /// <param name="type">装饰器类型</param>
        /// <returns></returns>
        public static Adorner GetOrAddAdorner(this UIElement uIElement, Type type)
        {
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(uIElement);

            if (adornerLayer == null)
            {
                throw new Exception("VisualParents Must have AdornerDecorator!");
            }
            var adorner = adornerLayer.GetAdorners(uIElement)?.FirstOrDefault(x => x?.GetType() == type);

            if (adorner == null)
            {
                lock (uIElement)
                {
                    if (adorner == null)
                    {
                        adorner = (Adorner)Activator.CreateInstance(type, new object[] { uIElement });
                        adornerLayer.Add(adorner);
                    }
                }
            }
            return(adorner);
        }
Esempio n. 8
0
        private static void AddAdorner(UIElement rec)
        {
            adornerLayer = AdornerLayer.GetAdornerLayer(rec);
            System.Diagnostics.Debug.Assert(adornerLayer != null, "Oops, you have not defined an AdornerDecorator in the template, check the generic.xaml file.");
            if (adornerLayer == null)
            {
                return;
            }
            if (adornerLayer.GetAdorners(rec) == null)
            {
                ResizingAdorner rad = new ResizingAdorner(rec);

                if (rec is Connectable)
                {
                    rad.HeightEnabled = (rec as Connectable).ResizableHeight;
                    rad.WidthEnabled  = (rec as Connectable).ResizableWidth;
                    rad.MinHeight     = (rec as Connectable).MinHeight;
                    rad.MinWidth      = (rec as Connectable).MinWidth;
                }

                adornerLayer.Add(rad);
            }
        }
        // Quand une nouvelle nouvelle stroke a ete ajoute
        private void surfaceDessin_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            if ((DataContext as VueModele)?.OutilSelectionne == "crayon" && surfaceDessin.SelectedStrokes.Count > 0)
            {
                CustomStroke newStroke = (DataContext as VueModele).AddStrokeFromView(
                    (CustomStroke)surfaceDessin.SelectedStrokes[0]
                    );
                surfaceDessin.Select(new StrokeCollection {
                    newStroke
                });
                if (newStroke.GetType() != typeof(LinkStroke))
                {
                    Path path = new Path();
                    path.Data = new RectangleGeometry(newStroke.GetBounds());
                    surfaceDessin.Children.Add(path);
                    AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(path);
                    myAdornerLayer.Add(new RotateAdorner(path, newStroke, surfaceDessin));
                    myAdornerLayer.Add(new AnchorPointAdorner(path, newStroke, surfaceDessin));
                    Adorner[] ad = myAdornerLayer.GetAdorners(path);
                    myAdornerLayer.Add(new EditionAdorner(path, newStroke, surfaceDessin));
                }
            }
            else
            {
                foreach (CustomStroke stroke in surfaceDessin.GetSelectedStrokes())
                {
                    if (stroke is LinkStroke)
                    {
                        surfaceDessin.modifyLinkStrokePath(stroke as LinkStroke, e.GetPosition(surfaceDessin));
                    }
                }
            }


            // Pour que les boutons soient de la bonne couleur
            (DataContext as VueModele)?.ChoisirOutil.Execute("lasso");
        }
Esempio n. 10
0
        private static void ShowValidationBorder(UIElement element, bool show)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);

              // Element not jet loaded
              if (layer is null) return;

              ValidationBorder adorner = (ValidationBorder)layer.GetAdorners(element)?.First();

              if (adorner is null)
              {
            adorner = new ValidationBorder(element);
            AdornerLayer.GetAdornerLayer(element).Add(adorner);
              }

              if (element.IsVisible && show)
              {
            adorner.Visibility = Visibility.Visible;
              }
              else
              {
            adorner.Visibility = Visibility.Collapsed;
              }
        }
Esempio n. 11
0
        /// <summary>
        /// Remove the placeholder from the specified element
        /// </summary>
        /// <param name="control">Element from which to remove the placeholder</param>
        private static void RemovePlaceholder(UIElement control)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            // layer could be null if control is no longer in the visual tree
            if (layer != null)
            {
                Adorner[] adorners = layer.GetAdorners(control);

                if (adorners == null)
                {
                    return;
                }

                foreach (Adorner adorner in adorners)
                {
                    if (adorner is PlaceholderAdorner)
                    {
                        adorner.Visibility = Visibility.Hidden;
                        layer.Remove(adorner);
                    }
                }
            }
        }
Esempio n. 12
0
        private static void IsSelectedPropertyChangedCallback(DependencyObject d,
                                                              DependencyPropertyChangedEventArgs e)
        {
            var          roiControl = (RoiControl)d;
            AdornerLayer layer      = roiControl.AdornerLayer;

            System.Windows.Documents.Adorner[] adorners = layer.GetAdorners(roiControl);
            if (roiControl.IsSelected)
            {
                foreach (System.Windows.Documents.Adorner adorner in adorners)
                {
                    adorner.Visibility = Visibility.Visible;
                }
            }
            else
            {
                foreach (System.Windows.Documents.Adorner adorner in adorners)
                {
                    adorner.Visibility = Visibility.Collapsed;
                }
            }

            roiControl.IsSelected.WriteLine();
        }
        static IEnumerable <Adorner> RemoveAdorner(UIElement adornedElement, Type adornerType)
        {
            Fx.Assert(adornedElement != null, "Invalid argument");
            Fx.Assert(typeof(Adorner).IsAssignableFrom(adornerType), "Invalid argument");
            List <Adorner> adornersRemoved = new List <Adorner>();
            AdornerLayer   adornerLayer    = AdornerLayer.GetAdornerLayer(adornedElement);

            if (adornerLayer != null)
            {
                Adorner[] adorners = adornerLayer.GetAdorners(adornedElement);
                if (adorners != null)
                {
                    foreach (Adorner adorner in adorners)
                    {
                        if (adornerType.IsAssignableFrom(adorner.GetType()))
                        {
                            adornerLayer.Remove(adorner);
                            adornersRemoved.Add(adorner);
                        }
                    }
                }
            }
            return(adornersRemoved);
        }
Esempio n. 14
0
        void RemoveBorderAdorner(UIElement adornedElement)
        {
            if (adornedElement != null)
            {
                AdornerLayer layr = AdornerLayer.GetAdornerLayer(adornedElement);
                if (layr != null)
                {
                    Adorner[] adorners = layr.GetAdorners(adornedElement);
                    if (adorners != null)
                    {
                        foreach (Adorner adr in adorners)
                        {
                            BorderAdorner badr = adr as BorderAdorner;

                            if (badr != null)
                            {
                                layr.Remove(badr);
                                badr.DisposeDragging();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        private static void RemoveCueBanner(UIElement control)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            if (layer == null)
            {
                return;
            }

            Adorner[] adorners = layer.GetAdorners(control);
            if (adorners == null)
            {
                return;
            }

            foreach (Adorner adorner in adorners)
            {
                if (adorner is CueBannerContentAdorner)
                {
                    adorner.Visibility = Visibility.Hidden;
                    layer.Remove(adorner);
                }
            }
        }
Esempio n. 16
0
 public static Boolean HasAdorner <T>(this AdornerLayer layer, UIElement element)
     where T : Adorner
 => layer.GetAdorners(element)?.OfType <T>().Any() ?? false;
Esempio n. 17
0
        //public static void ShowLoading(this UIElement element, bool isAutoClose=false)
        //{
        //    ShowLoading(element, string.Empty, string.Empty, 60, HorizontalAlignment.Center, VerticalAlignment.Center, null, null, false, Brushes.Gray, null);
        //    Task.Factory.StartNew(() =>
        //    {
        //        Task.Delay(10 * 1000);
        //        if (element == null || element.Dispatcher == null) return;
        //        element.Dispatcher.BeginInvoke(new Action(() => { element.HideLoading(); }));
        //    });
        //}

        //public static void UpdateLoading(this UIElement element, string Percent = "", string LoadingName = "")
        //{
        //    ShowLoading(element, Percent, LoadingName, 60, HorizontalAlignment.Center, VerticalAlignment.Center, null, null, false, Brushes.Gray, null);
        //}

        public static void HideLoading(this UIElement element, bool disableElement = false)
        {
            if (element == null || element.Dispatcher == null)
            {
                return;
            }
            if (element.Dispatcher.CheckAccess())
            {
                element.IsEnabled        = !disableElement;
                element.IsHitTestVisible = true;
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);
                if (layer == null)
                {
                    var win = element as Window;
                    if (win != null && win.Content != null && win.Content is UIElement)
                    {
                        element = win.Content as UIElement;
                        layer   = AdornerLayer.GetAdornerLayer(element);
                    }
                    else if (element is FrameworkElement)
                    {
                        FrameworkElement fe = element as FrameworkElement;
                        if (!fe.IsLoaded)
                        {
                            lock (list)
                            {
                                ShowLoadingContext target = null;
                                foreach (var p in list)
                                {
                                    if (p.Target == fe)
                                    {
                                        target = p;
                                        break;
                                    }
                                }

                                if (target != null)
                                {
                                    list.Remove(target);
                                }
                            }

                            fe.Loaded -= OnFrameworkElementLoaded;
                            return;
                        }
                    }
                }

                if (layer != null)
                {
                    LoadingAdorner target = null;
                    var            items  = layer.GetAdorners(element);
                    if (items != null)
                    {
                        foreach (var item in items)
                        {
                            if (item is LoadingAdorner)
                            {
                                target = item as LoadingAdorner;
                                if (target != null)
                                {
                                    layer.Remove(target);
                                    target.Dispose();
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Action <UIElement, Boolean> action = HideLoading;
                element.Dispatcher.BeginInvoke(action, element, disableElement);
            }
        }
Esempio n. 18
0
        public static void ShowLoading(this UIElement element,
                                       string Percent,
                                       string LoadingName,
                                       double loadingSize = 60,
                                       HorizontalAlignment horizontalAlignment = HorizontalAlignment.Center,
                                       VerticalAlignment verticalAlignment     = VerticalAlignment.Center,
                                       Thickness?margin    = null,
                                       Size?size           = null,
                                       bool disableElement = false,
                                       Brush background    = null,
                                       Brush foreground    = null)
        {
            element.IsEnabled = !disableElement;

            if (element == null || element.Dispatcher == null)
            {
                return;
            }
            if (element.Dispatcher.CheckAccess())
            {
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);
                if (layer == null)
                {
                    var win = element as Window;
                    element.IsHitTestVisible = false;
                    if (win != null && win.Content != null && win.Content is UIElement)
                    {
                        element = win.Content as UIElement;
                        //var tag = ((Grid) element).Tag as UIElement;
                        //if (tag != null)
                        //{
                        //    layer = AdornerLayer.GetAdornerLayer(tag);
                        //    element = tag;
                        //}
                        //else
                        //{
                        //    layer = AdornerLayer.GetAdornerLayer(element);
                        //}
                        layer = AdornerLayer.GetAdornerLayer(element);
                    }
                    else if (element is FrameworkElement)
                    {
                        FrameworkElement fe = element as FrameworkElement;
                        if (!fe.IsLoaded)
                        {
                            //此处用匿名委托的好处是ShowLoading的参数可以直接传到匿名委托中,但是却没有办法在HideLoading时注销此匿名委托
                            //在控件未 load 之前调用 ShowLoading 再立刻调用HideLoading时 就会发现控件在Loaded之后会显示遮罩,却无法消失
                            //RoutedEventHandler handler = null;
                            //handler = (s, e) =>
                            //{
                            //    fe.Loaded -= handler;
                            //    (s as FrameworkElement).ShowLoading(loadingSize, horizontalAlignment, verticalAlignment, margin, size);
                            //};
                            //fe.Loaded += handler;

                            ShowLoadingContext p = new ShowLoadingContext {
                                Target = fe, LoadingSize = loadingSize, HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAlignment, Margin = margin, Size = size, percent = Percent, loadingName = LoadingName
                            };
                            lock (list)
                            {
                                var exist = false;
                                foreach (var item in list)
                                {
                                    if (item.Target == fe)
                                    {
                                        item.LoadingSize         = loadingSize;
                                        item.HorizontalAlignment = horizontalAlignment;
                                        item.VerticalAlignment   = verticalAlignment;
                                        item.Margin = margin;
                                        item.Size   = size;
                                        exist       = true;
                                        break;
                                    }
                                }

                                if (!exist)
                                {
                                    list.Add(p);
                                    fe.Loaded += OnFrameworkElementLoaded;
                                }
                            }

                            return;
                        }
                    }
                }

                if (layer != null)
                {
                    var  ads      = layer.GetAdorners(element);
                    bool hasFound = false;
                    if (ads != null)
                    {
                        foreach (var ad in ads)
                        {
                            if (ad is LoadingAdorner)
                            {
                                var loading = ad as LoadingAdorner;
                                loading.UpdateLoading(Percent, LoadingName);
                                hasFound = true;
                            }
                        }
                    }

                    if (!hasFound)
                    {
                        layer.Add(new LoadingAdorner(element, Percent, LoadingName)
                        {
                            LoadingSize = loadingSize,
                            LoadingVerticalAlignment   = verticalAlignment,
                            LoadingHorizontalAlignment = horizontalAlignment,
                            LoadingMargin = margin ?? new Thickness(0, 0, 0, 0),
                            Size          = size ?? Size.Empty,
                            Foreground    = foreground,
                            Background    = background,
                        });
                    }
                }
            }
            else
            {
                Action <UIElement, string, string, Double, HorizontalAlignment, VerticalAlignment, Thickness?, Size?, bool, Brush, Brush> action = ShowLoading;
                element.Dispatcher.BeginInvoke(action, element, loadingSize, horizontalAlignment, verticalAlignment, margin, size, disableElement, background, foreground);
            }
        }
Esempio n. 19
0
 private static OverlayAdorner GetWatermarkAdorner(AdornerLayer layer, UIElement adornedElement) => layer.GetAdorners(adornedElement)?.OfType <OverlayAdorner>().FirstOrDefault();
Esempio n. 20
0
        private void paintCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            MauTo();
            currentPoint = e.GetPosition(paintCanvas);
            if (slElement != null)
            {
                if (MouseInside)
                {
                    startPoint    = e.GetPosition(paintCanvas);
                    _originalLeft = Canvas.GetLeft(slElement);
                    _originalTop  = Canvas.GetTop(slElement);
                    return;
                }
            }
            if (selected)
            {
                selected = false;
                if (slElement != null)
                {
                    aLayer.Remove(aLayer.GetAdorners(slElement)[0]);
                    slElement = null;
                }
                _isDown = false;
                return;
            }

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                startPaint = true;

                if (tag == 1)
                {
                    lastLine                 = new Line();
                    lastLine.Stroke          = myBrush.Clone();
                    lastLine.Fill            = color2;
                    lastLine.StrokeThickness = size;
                    lastLine.StrokeDashArray = lineType;
                    lastLine.X1              = currentPoint.X;
                    lastLine.Y1              = currentPoint.Y;

                    paintCanvas.Children.Add(lastLine);
                }


                if (tag == 2 || tag == 3)
                {
                    lastRectangle                 = new Rectangle();
                    lastRectangle.Stroke          = myBrush.Clone();
                    lastRectangle.Fill            = color2;
                    lastRectangle.StrokeThickness = size;
                    lastRectangle.StrokeDashArray = lineType;

                    Canvas.SetLeft(lastRectangle, currentPoint.X);
                    Canvas.SetTop(lastRectangle, currentPoint.Y);
                    paintCanvas.Children.Add(lastRectangle);
                }



                if (tag == 4 || tag == 5)
                {
                    lastEllipse                 = new Ellipse();
                    lastEllipse.Stroke          = myBrush.Clone();
                    lastEllipse.Fill            = color2;
                    lastEllipse.StrokeThickness = size;
                    lastEllipse.StrokeDashArray = lineType;

                    Canvas.SetLeft(lastEllipse, currentPoint.X);
                    Canvas.SetTop(lastEllipse, currentPoint.Y);

                    paintCanvas.Children.Add(lastEllipse);
                }
            }

            if (tag == 6)
            {
                lastArrow                 = new Polygon();
                lastArrow.Stroke          = myBrush.Clone();
                lastArrow.Fill            = color2;
                lastArrow.StrokeThickness = size;
                lastArrow.StrokeDashArray = lineType;

                Canvas.SetLeft(lastArrow, currentPoint.X);
                Canvas.SetTop(lastArrow, currentPoint.Y);
                paintCanvas.Children.Add(lastArrow);
            }
            if (tag == 7)
            {
                lastStar                 = new Polygon();
                lastStar.Stroke          = myBrush.Clone();
                lastStar.Fill            = color2;
                lastStar.StrokeThickness = size;
                lastStar.StrokeDashArray = lineType;

                Canvas.SetLeft(lastStar, currentPoint.X);
                Canvas.SetTop(lastStar, currentPoint.Y);
                paintCanvas.Children.Add(lastStar);
            }

            if (tag == 8)
            {
                lastHeart                 = new System.Windows.Shapes.Path();
                lastHeart.Stroke          = myBrush.Clone();
                lastHeart.Fill            = color2;
                lastHeart.StrokeThickness = size;
                lastHeart.StrokeDashArray = lineType;

                Canvas.SetLeft(lastHeart, currentPoint.X);
                Canvas.SetTop(lastHeart, currentPoint.Y);
                paintCanvas.Children.Add(lastHeart);
            }
            e.Handled = true;
        }
Esempio n. 21
0
        public static void GoBabyGo()
        {
            tempWindow = new MainWindow();
            tempWindow.Show();

            Application.Current.MainWindow.AddHandler(UIElement.PreviewMouseDownEvent, new MouseButtonEventHandler((o, e) =>
            {
                FrameworkElement element = e.OriginalSource as FrameworkElement;

                if (element != null)
                {
                    //Label l = new Label() { Content = PathToString(GenerateTypePath(GetNearestLogicalParent(element))) };
                    Label l = new Label()
                    {
                        Content = PathToString(GenerateTypePath(element))
                    };
                    DockPanel.SetDock(l, Dock.Top);
                    tempWindow.MainStackPanel.Children.Add(l);
                }
            }), true);

            Application.Current.MainWindow.AddHandler(UIElement.PreviewMouseMoveEvent, new MouseEventHandler((o, e) =>
            {
                FrameworkElement element = e.OriginalSource as FrameworkElement;

                if (element != null)
                {
                    //element = GetNearestLogicalParent(element);

                    if (element != adornedElement)
                    {
                        if (adornedElement != null)
                        {
                            AdornerLayer oldElementLayer = AdornerLayer.GetAdornerLayer(adornedElement);

                            if (oldElementLayer != null)
                            {
                                Adorner[] toRemoveArray = oldElementLayer.GetAdorners(adornedElement);
                                if (toRemoveArray != null)
                                {
                                    foreach (Adorner a in toRemoveArray)
                                    {
                                        if (a is BorderAdorner)
                                        {
                                            oldElementLayer.Remove(a);
                                        }
                                    }
                                }
                            }
                        }

                        AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);
                        if (layer != null)
                        {
                            BorderAdorner ba    = new BorderAdorner(element);
                            ba.IsHitTestVisible = false;
                            layer.Add(ba);
                        }

                        adornedElement = element;
                    }
                }
            }), true);
        }
Esempio n. 22
0
 public Adorner[] GetAdorners(UIElement adornedElement)
 {
     return(_adornerLayer.GetAdorners(adornedElement));
 }
Esempio n. 23
0
        private void paintCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            startPoint = e.GetPosition(paintCanvas);

            if (check_element != null)
            {
                if (ins)
                {
                    startPoint = e.GetPosition(paintCanvas);
                    OLeft      = Canvas.GetLeft(check_element);
                    OTop       = Canvas.GetTop(check_element);
                    return;
                }
            }
            if (sl)
            {
                sl = false;
                if (check_element != null)
                {
                    Layer.Remove(Layer.GetAdorners(check_element)[0]);
                    check_element = null;
                }
                isMouseDowned = false;
                return;
            }

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (clickedLine)
                {
                    lastLine = new Line();
                    if (StrokeColor == null)
                    {
                        lastLine.Stroke = System.Windows.Media.Brushes.Black;
                    }
                    else
                    {
                        lastLine.Stroke = StrokeColor;
                    }
                    if (fill != null)
                    {
                        lastLine.Fill = fill;
                    }
                    else
                    {
                        lastLine.Fill = System.Windows.Media.Brushes.White;
                    }
                    lastLine.StrokeThickness = Thick;
                    if (style_line == 2)
                    {
                        lastLine.StrokeDashArray = new DoubleCollection()
                        {
                            1, 2
                        }
                    }
                    ;
                    if (style_line == 3)
                    {
                        lastLine.StrokeDashArray = new DoubleCollection()
                        {
                            8
                        }
                    }
                    ;

                    lastLine.X1 = startPoint.X;
                    lastLine.Y1 = startPoint.Y;

                    paintCanvas.Children.Add(lastLine);
                }
            }

            if (clickedRect || clikedSqr)
            {
                rec = new Rectangle();
                if (StrokeColor == null)
                {
                    rec.Stroke = System.Windows.Media.Brushes.Black;
                }
                else
                {
                    rec.Stroke = StrokeColor;
                }
                if (fill != null)
                {
                    rec.Fill = fill;
                }
                else
                {
                    rec.Fill = System.Windows.Media.Brushes.White;
                }
                rec.StrokeThickness = Thick;
                if (style_line == 2)
                {
                    rec.StrokeDashArray = new DoubleCollection()
                    {
                        1, 2
                    }
                }
                ;
                if (style_line == 3)
                {
                    rec.StrokeDashArray = new DoubleCollection()
                    {
                        8
                    }
                }
                ;
                Canvas.SetLeft(rec, startPoint.X);
                Canvas.SetTop(rec, startPoint.X);
                paintCanvas.Children.Add(rec);
            }

            if (clickedEll || clickedCir)
            {
                el = new Ellipse();
                if (StrokeColor == null)
                {
                    el.Stroke = System.Windows.Media.Brushes.Black;
                }
                else
                {
                    el.Stroke = StrokeColor;
                }
                if (fill != null)
                {
                    el.Fill = fill;
                }
                else
                {
                    el.Fill = System.Windows.Media.Brushes.White;
                }
                el.StrokeThickness = Thick;

                if (style_line == 2)
                {
                    el.StrokeDashArray = new DoubleCollection()
                    {
                        1, 2
                    }
                }
                ;
                if (style_line == 3)
                {
                    el.StrokeDashArray = new DoubleCollection()
                    {
                        8
                    }
                }
                ;
                Canvas.SetLeft(el, startPoint.X);
                Canvas.SetTop(el, startPoint.X);
                paintCanvas.Children.Add(el);
            }

            if (clickedArr)
            {
                Arrow = new Polygon();
                if (StrokeColor == null)
                {
                    Arrow.Stroke = System.Windows.Media.Brushes.Black;
                }
                else
                {
                    Arrow.Stroke = StrokeColor;
                }
                if (fill != null)
                {
                    Arrow.Fill = fill;
                }
                else
                {
                    Arrow.Fill = System.Windows.Media.Brushes.White;
                }
                Arrow.StrokeThickness = Thick;

                if (style_line == 2)
                {
                    Arrow.StrokeDashArray = new DoubleCollection()
                    {
                        1, 2
                    }
                }
                ;
                if (style_line == 3)
                {
                    Arrow.StrokeDashArray = new DoubleCollection()
                    {
                        8
                    }
                }
                ;

                Canvas.SetLeft(Arrow, startPoint.X);
                Canvas.SetTop(Arrow, startPoint.Y);
                paintCanvas.Children.Add(Arrow);
            }

            if (clickedHe)
            {
                Heart = new System.Windows.Shapes.Path();
                if (StrokeColor == null)
                {
                    Heart.Stroke = System.Windows.Media.Brushes.Black;
                }
                else
                {
                    Heart.Stroke = StrokeColor;
                }
                if (fill != null)
                {
                    Heart.Fill = fill;
                }
                else
                {
                    Heart.Fill = System.Windows.Media.Brushes.White;
                }
                Heart.StrokeThickness = Thick;

                if (style_line == 2)
                {
                    Heart.StrokeDashArray = new DoubleCollection()
                    {
                        1, 2
                    }
                }
                ;
                if (style_line == 3)
                {
                    Heart.StrokeDashArray = new DoubleCollection()
                    {
                        8
                    }
                }
                ;

                Canvas.SetLeft(Heart, startPoint.X);
                Canvas.SetTop(Heart, startPoint.Y);
                paintCanvas.Children.Add(Heart);
            }

            if (clickedSta)
            {
                Star = new Polygon();
                if (StrokeColor == null)
                {
                    Star.Stroke = System.Windows.Media.Brushes.Black;
                }
                else
                {
                    Star.Stroke = StrokeColor;
                }
                if (fill != null)
                {
                    Star.Fill = fill;
                }
                else
                {
                    Star.Fill = System.Windows.Media.Brushes.White;
                }
                Star.StrokeThickness = Thick;

                if (style_line == 2)
                {
                    Star.StrokeDashArray = new DoubleCollection()
                    {
                        1, 2
                    }
                }
                ;
                if (style_line == 3)
                {
                    Star.StrokeDashArray = new DoubleCollection()
                    {
                        8
                    }
                }
                ;

                Canvas.SetLeft(Star, startPoint.X);
                Canvas.SetTop(Star, startPoint.Y);
                paintCanvas.Children.Add(Star);
            }
        }
Esempio n. 24
0
        /// <summary>
        ///   Invoked whenever <see cref="Placeholder" />.HideOnFocus attached property is changed.
        /// </summary>
        /// <param name="sender">
        ///   The object where the event handler is attached.
        /// </param>
        /// <param name="e">
        ///   Provides data about the event.
        /// </param>
        private static void OnHideOnFocusChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            bool hideOnFocus = (bool)e.NewValue;

            if ((bool)e.OldValue == hideOnFocus)
            {
                return;
            }

            Control adornedElement = sender as Control;

            if (!(adornedElement is TextBox || adornedElement is PasswordBox || adornedElement is RichTextBox))
            {
                if (!adornedElement.IsLoaded)
                {
                    adornedElement.Loaded += ChangeHideOnFocus;
                }
                else
                {
                    TextBox templateTextBox = FindTextBox(adornedElement);
                    if (templateTextBox != null)
                    {
                        Placeholder.SetHideOnFocus(templateTextBox, (bool)e.NewValue);
                    }
                }

                return;
            }

            Placeholder  placeholder  = null;
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);

            if (adornerLayer == null)
            {
                return;
            }

            Adorner[] adorners = adornerLayer.GetAdorners(adornedElement);
            if (adorners != null)
            {
                foreach (Adorner adorner in adorners)
                {
                    placeholder = adorner as Placeholder;
                    if (placeholder != null)
                    {
                        break;
                    }
                }
            }

            if (placeholder == null)
            {
                return;
            }

            if (adornedElement.IsLoaded)
            {
                if (hideOnFocus)
                {
                    adornedElement.GotFocus  += placeholder.AdornedElement_GotFocus;
                    adornedElement.LostFocus += placeholder.AdornedElement_LostFocus;
                    if (adornedElement.IsFocused && placeholder.isPlaceholderVisible)
                    {
                        placeholder.InvalidateVisual();
                    }
                }
                else
                {
                    adornedElement.GotFocus  -= placeholder.AdornedElement_GotFocus;
                    adornedElement.LostFocus -= placeholder.AdornedElement_LostFocus;
                    placeholder.AdornedElement_LostFocus(adornedElement, new RoutedEventArgs(UIElement.LostFocusEvent, placeholder));
                }
            }
            else
            {
                adornedElement.Loaded += AdornedElement_Loaded;
            }
        }
Esempio n. 25
0
 public void UpdatePosition(double left, double top)
 {
     _x = left - _width / 2;
     _y = top - _height / 2;
     if (_adornerLayer != null && AdornedElement != null && _contentPresenter.Content != null && _adornerLayer.GetAdorners(AdornedElement) != null)
     {
         _adornerLayer.Update(AdornedElement);
     }
 }
        public static void GoBabyGo()
        {
            crWindow = new ClickyRecordingWindow();
            crWindow.Show();

            Application.Current.MainWindow.AddHandler(UIElement.PreviewMouseDownEvent, new MouseButtonEventHandler((o, e) =>
            {
                if (TutorialManager.CurrentTutorial == null)
                {
                    FrameworkElement element = e.OriginalSource as FrameworkElement;

                    if (element != null)
                    {
                        //Label l = new Label() { Content = PathToString(GenerateTypePath(GetNearestLogicalParent(element))) };
                        //Label l = new Label() { Content = PathToString(GenerateTypePath(element)) };
                        //DockPanel.SetDock(l, Dock.Top);
                        ((ClickyRecordingViewModel)crWindow.DataContext).RecordedClicks.Add(new Step(GenerateTypePath(element)));
                    }
                }
            }), true);

            Application.Current.MainWindow.AddHandler(UIElement.PreviewMouseMoveEvent, new MouseEventHandler((o, e) =>
            {
                if (TutorialManager.CurrentTutorial == null)
                {
                    FrameworkElement element = e.OriginalSource as FrameworkElement;

                    if (element != null)
                    {
                        //element = GetNearestLogicalParent(element);

                        if (element != adornedElement)
                        {
                            if (adornedElement != null)
                            {
                                AdornerLayer oldElementLayer = AdornerLayer.GetAdornerLayer(adornedElement);

                                if (oldElementLayer != null)
                                {
                                    Adorner[] toRemoveArray = oldElementLayer.GetAdorners(adornedElement);
                                    if (toRemoveArray != null)
                                    {
                                        foreach (Adorner a in toRemoveArray)
                                        {
                                            if (a is BorderAdorner)
                                            {
                                                oldElementLayer.Remove(a);
                                            }
                                        }
                                    }
                                }
                            }

                            AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);
                            if (layer != null)
                            {
                                BorderAdorner ba    = new BorderAdorner(element);
                                ba.IsHitTestVisible = false;
                                layer.Add(ba);
                            }

                            adornedElement = element;
                        }
                    }
                }
            }), true);
        }