Beispiel #1
0
 private static void OnContextMenuDeclarationChanged(DependencyObject source,
                                                     DependencyPropertyChangedEventArgs e)
 {
     if (source is ConnectorUI me)
     {
         if (e.NewValue is IList <ICommandDescriptor> commands)
         {
             if (me._model.AllowWaypoints)
             {
                 commands.Add(CreateAddWaypointMenuItem(me));
             }
             me.ContextMenu = OutlineHelper.InitContextMenu(commands);
         }
     }
 }
Beispiel #2
0
        void InitContextMenu(ConnectableBase model)
        {
            Sketch.Helper.RuntimeCheck.Contract.Requires <ArgumentNullException>(model != null, "InitContextMenu() requires valide model");
            var commands = model.Commands;

            if (commands != null && commands.Count > 0)
            {
                ContextMenu = OutlineHelper.InitContextMenu(commands);
                if (_model.CanCopy && _model.IsSerializable)
                {
                    ContextMenu.Items.Add(
                        new MenuItem()
                    {
                        Header  = "Copy",
                        Command = new DelegateCommand(() =>
                        {
                            var newElem = _model.Clone();
                            var t       = new TranslateTransform(
                                ConnectableBase.DefaultWidth / 4,
                                ConnectableBase.DefaultHeight / 4);
                            newElem.Move(t);
                            _parent.SketchItems.Add(newElem);
                        })
                    });
                }
                if (_model.CanChangeZorder)
                {
                    var z = Canvas.GetZIndex(this);
                    ContextMenu.Items.Add(
                        new MenuItem()
                    {
                        Header  = "Bring to front",
                        Command = new DelegateCommand(() =>
                        {
                            GetMinMaxZ(out int minZ, out int maxZ);
                            Canvas.SetZIndex(this, maxZ + 1);
                        })
                    });