Esempio n. 1
0
        protected static void AnnotationsIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue && GetContent(d) == null)
            {
                var image     = d as Image;
                var uielement = d as FrameworkElement;
                var width     = image?.Source?.Width ?? uielement.Width;
                var height    = image?.Source?.Height ?? uielement.Height;
                AdornmentCollection layers = new AdornmentCollection();

                SetAnnotationsLayer(d, new AnnotationsControl((FrameworkElement)d)
                {
                    Name = "AnnotationsLayer", ContainerWidth = width, ContainerHeight = height
                });
                SetActionsLayer(d, CanvasLayer.New <ActionsAnnotationAdorner>((FrameworkElement)d, "ActionsLayer"));
                SetMenuLayer(d, CanvasLayer.New <UIElement>((FrameworkElement)d, "MenuLayer"));
                GetMenuLayer(d).AnnotationsControl = GetAnnotationsLayer(d);
                var controlMenu = new AnnotationsControlMenu();
                controlMenu.SetBinding(FrameworkElement.VisibilityProperty, new Binding(AnnotationsControl.IsInEditModeProperty.Name)
                {
                    Source = GetAnnotationsLayer(d), Converter = new BoolToVisibilityConverter()
                });
                GetMenuLayer(d).GetItemsSource <UIElement>().Add(controlMenu);

                layers.Add(GetAnnotationsLayer(d));
                layers.Add(GetActionsLayer(d));
                layers.Add(GetMenuLayer(d));

                SetContent(d, layers);

                SetAnnotationsChangedDelegate(d, (sender, changedEventArgs) =>
                {
                    switch (changedEventArgs.Action)
                    {
                    case NotifyCollectionChangedAction.Add:
                        changedEventArgs.NewItems.OfType <AnnotationBase>().ToList().ForEach(_ => GetActionsLayer(d).GetItemsSource <ActionsAnnotationAdorner>().Add(_.ActionsAdorner));
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        changedEventArgs.OldItems.OfType <AnnotationBase>().ToList().ForEach(_ => GetActionsLayer(d).GetItemsSource <ActionsAnnotationAdorner>().Remove(_.ActionsAdorner));
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        GetActionsLayer(d).GetItemsSource <ActionsAnnotationAdorner>().Clear();
                        break;

                    default:
                        break;
                    }
                });
                GetAnnotationsLayer(d).Annotations.CollectionChanged += GetAnnotationsChangedDelegate(d);
            }
            SetIsVisible(d, (bool)e.NewValue);
        }
Esempio n. 2
0
 public static void SetMenuLayer(DependencyObject element, CanvasLayer value) => element.SetValue(MenuLayerProperty, value);