Esempio n. 1
0
        /// <summary>
        /// Method to create Node
        /// </summary>
        /// <param name="offsetx"></param>
        /// <param name="offsety"></param>
        /// <param name="annotation"></param>
        /// <param name="shapestyle"></param>
        /// <param name="id"></param>
        /// <param name="parentid"></param>
        /// <returns></returns>
        private CustomNode CreateNode(double offsetx, double offsety, string annotation, string shapestyle, string id, string parentid)
        {
            CustomNode node = new CustomNode()
            {
                OffsetX     = offsetx,
                OffsetY     = offsety,
                UnitHeight  = 60,
                UnitWidth   = 60,
                Id          = id,
                ParentId    = parentid,
                Shape       = App.Current.Resources["Ellipse"],
                Annotations = new ObservableCollection <TextAnnotationViewModel>()
                {
                    new TextAnnotationViewModel()
                    {
                        Text = annotation,
                    },
                }
            };

            if (shapestyle == "Red")
            {
                node.ThemeStyleId = StyleId.Moderate | StyleId.Accent6;
            }

            else if (shapestyle == "Yellow")
            {
                node.ThemeStyleId = StyleId.Moderate | StyleId.Accent7;
            }

            else if (shapestyle == "Green")
            {
                node.ThemeStyleId = StyleId.Intense | StyleId.Accent5;
            }

            else if (shapestyle == "Violet")
            {
                node.ThemeStyleId = StyleId.Intense | StyleId.Accent2;
            }

            return(node);
        }
Esempio n. 2
0
        public DiagramVM()
        {
            #region Properties

            Constraints = Constraints.Add(GraphConstraints.Undoable);

            DefaultConnectorType = ConnectorType.Line;

            SelectedItems = new SelectorViewModel()
            {
                SelectorConstraints = SelectorConstraints.Default & ~SelectorConstraints.QuickCommands,
            };
            Theme            = new LinearTheme();
            Theme.NodeStyles = (Theme as LinearTheme).VariantStyles[1];


            #endregion

            #region Nodes and Connectors Creation

            CustomNode Node1  = CreateNode(550, 100, "A", "SkyBlue", "1", "");
            CustomNode Node2  = CreateNode(450, 200, "B", "Red", "2", "1");
            CustomNode Node3  = CreateNode(550, 200, "C", "Red", "3", "1");
            CustomNode Node4  = CreateNode(650, 200, "D", "Red", "4", "1");
            CustomNode Node5  = CreateNode(400, 300, "E", "Yellow", "5", "2");
            CustomNode Node6  = CreateNode(500, 300, "F", "Yellow", "6", "2");
            CustomNode Node7  = CreateNode(600, 300, "G", "Yellow", "7", "4");
            CustomNode Node8  = CreateNode(700, 300, "H", "Yellow", "8", "4");
            CustomNode Node9  = CreateNode(450, 400, "I", "Violet", "9", "6");
            CustomNode Node10 = CreateNode(550, 400, "J", "Violet", "10", "6");
            CustomNode Node11 = CreateNode(650, 400, "K", "Violet", "11", "8");
            CustomNode Node12 = CreateNode(750, 400, "L", "Violet", "12", "8");
            CustomNode Node13 = CreateNode(400, 500, "M", "Green", "13", "9");
            CustomNode Node14 = CreateNode(500, 500, "N", "Green", "14", "9");
            CustomNode Node15 = CreateNode(600, 500, "O", "Green", "15", "11");
            CustomNode Node16 = CreateNode(700, 500, "P", "Green", "16", "11");
            CustomNode Node17 = CreateNode(450, 600, "Q", "SkyBlue", "17", "14");
            CustomNode Node18 = CreateNode(550, 600, "R", "SkyBlue", "18", "14");
            CustomNode Node19 = CreateNode(650, 600, "S", "SkyBlue", "19", "16");
            CustomNode Node20 = CreateNode(750, 600, "T", "SkyBlue", "20", "16");

            (Nodes as NodeCollection).Add(Node1);
            (Nodes as NodeCollection).Add(Node2);
            (Nodes as NodeCollection).Add(Node3);
            (Nodes as NodeCollection).Add(Node4);
            (Nodes as NodeCollection).Add(Node5);
            (Nodes as NodeCollection).Add(Node6);
            (Nodes as NodeCollection).Add(Node7);
            (Nodes as NodeCollection).Add(Node8);
            (Nodes as NodeCollection).Add(Node9);
            (Nodes as NodeCollection).Add(Node10);
            (Nodes as NodeCollection).Add(Node11);
            (Nodes as NodeCollection).Add(Node12);
            (Nodes as NodeCollection).Add(Node13);
            (Nodes as NodeCollection).Add(Node14);
            (Nodes as NodeCollection).Add(Node15);
            (Nodes as NodeCollection).Add(Node16);
            (Nodes as NodeCollection).Add(Node17);
            (Nodes as NodeCollection).Add(Node18);
            (Nodes as NodeCollection).Add(Node19);
            (Nodes as NodeCollection).Add(Node20);

            CreateConnector(Node1, Node2);
            CreateConnector(Node1, Node3);
            CreateConnector(Node1, Node4);
            CreateConnector(Node2, Node5);
            CreateConnector(Node2, Node6);
            CreateConnector(Node4, Node7);
            CreateConnector(Node4, Node8);
            CreateConnector(Node6, Node9);
            CreateConnector(Node6, Node10);
            CreateConnector(Node8, Node11);
            CreateConnector(Node8, Node12);
            CreateConnector(Node9, Node13);
            CreateConnector(Node9, Node14);
            CreateConnector(Node11, Node15);
            CreateConnector(Node11, Node16);
            CreateConnector(Node14, Node17);
            CreateConnector(Node14, Node18);
            CreateConnector(Node16, Node19);
            CreateConnector(Node16, Node20);

            #endregion

            #region Commands and CommandManager

            // Custom command and Modified Commands

            CustomGroup   = new Command(OnCustomGroupCommand);
            CustomUngroup = new Command(OnCustomUngroupCommand);
            ChildNode     = new Command(OnChildNodeCommand);
            ParentNode    = new Command(OnParentNodeCommand);
            NextChild     = new Command(OnNextChildCommand);
            PreviousChild = new Command(OnPreviousChildCommand);

            ItemAddedCommand = new Command(OnItemAdded);

            CommandManager = new Syncfusion.UI.Xaml.Diagram.CommandManager();

            (CommandManager as Syncfusion.UI.Xaml.Diagram.CommandManager).Commands = new CommandCollection();

            (CommandManager.Commands as CommandCollection).Add
            (
                new GestureCommand()
            {
                Name    = "CustomGroup",
                Command = CustomGroup,
                Gesture = new Gesture
                {
                    KeyModifiers = ModifierKeys.Control,
                    KeyState     = KeyStates.Down,
                    Key          = System.Windows.Input.Key.G,
                },
            }
            );

            (CommandManager.Commands as CommandCollection).Add
            (
                new GestureCommand()
            {
                Name    = "CustomUngroup",
                Command = CustomUngroup,
                Gesture = new Gesture
                {
                    KeyModifiers = ModifierKeys.Control,
                    KeyState     = KeyStates.Down,
                    Key          = System.Windows.Input.Key.U,
                },
            }
            );


            (CommandManager.Commands as CommandCollection).Add
            (
                new GestureCommand()
            {
                Name    = "ChildNode",
                Command = ChildNode,
                Gesture = new Gesture
                {
                    KeyState = KeyStates.Down,
                    Key      = System.Windows.Input.Key.Down,
                },
            }
            );


            (CommandManager.Commands as CommandCollection).Add
            (
                new GestureCommand()
            {
                Name    = "ParentNode",
                Command = ParentNode,
                Gesture = new Gesture
                {
                    KeyState = KeyStates.Down,
                    Key      = System.Windows.Input.Key.Up,
                },
            }
            );

            (CommandManager.Commands as CommandCollection).Add
            (
                new GestureCommand()
            {
                Name    = "NextChild",
                Command = NextChild,
                Gesture = new Gesture
                {
                    KeyState = KeyStates.Down,
                    Key      = System.Windows.Input.Key.Right,
                },
            }
            );

            (CommandManager.Commands as CommandCollection).Add
            (
                new GestureCommand()
            {
                Name    = "PreviousChild",
                Command = PreviousChild,
                Gesture = new Gesture
                {
                    KeyState = KeyStates.Down,
                    Key      = System.Windows.Input.Key.Left,
                },
            }
            );

            #endregion
        }