Beispiel #1
0
        public DiagramVM()
        {
            PageSettings = new PageSettings()
            {
                PageBorderBrush = new SolidColorBrush(Colors.Transparent),
                PageBackground  = new SolidColorBrush(Colors.White)
            };
            ScrollSettings = new ScrollSettings()
            {
                ScrollLimit = ScrollLimit.Diagram
            };
            Menu = null;
            DataSourceSettings = new DataSourceSettings()
            {
                ParentId   = "ParentId",
                Id         = "EmpId",
                DataSource = GetData()
            };
            LayoutManager = new Syncfusion.UI.Xaml.Diagram.Layout.LayoutManager()
            {
                Layout = new DirectedTreeLayout()
                {
                    Type        = LayoutType.Hierarchical,
                    Orientation = TreeOrientation.LeftToRight,
                }
            };

            ItemDeletingCommand = new Command(OnItemDeleting);
        }
        public CustomDiagramViewModel()
        {
            #region Commands

            AddNode             = new Command(OnAddNode);
            DeleteNode          = new Command(OnDeleteNode);
            ItemAddedCommand    = new Command(OnItemAdded);
            ItemDeletingCommand = new Command(OnItemDeleting);
            ItemSelectedCommand = new Command(OnItemSelected);

            #endregion

            #region Initialize Properties

            Tool = Tool.SingleSelect;

            Datas = new ObservableCollection <Items>()
            {
                new Items()
                {
                    Name = "Plant Manager", ID = 1, SubItems = new ObservableCollection <Items>()
                    {
                        new Items()
                        {
                            Name = "Production Manager", ID = 2, ParentID = 1, SubItems = new ObservableCollection <Items>()
                            {
                                new Items()
                                {
                                    Name = "Control Room", ID = 3, ParentID = 2, SubItems = new ObservableCollection <Items>()
                                    {
                                        new Items()
                                        {
                                            Name = "Foreman1", ID = 4, ParentID = 3, SubItems = new ObservableCollection <Items>()
                                            {
                                                new Items()
                                                {
                                                    Name = "Craft Personnel5", ID = 5, ParentID = 4
                                                },
                                                new Items()
                                                {
                                                    Name = "Craft Personnel6", ID = 6, ParentID = 4
                                                },
                                            },
                                        },
                                    },
                                },
                                new Items()
                                {
                                    Name = "Plant Operator", ID = 7, ParentID = 2, SubItems = new ObservableCollection <Items>()
                                    {
                                        new Items()
                                        {
                                            Name = "Foreman2", ID = 8, ParentID = 7, SubItems = new ObservableCollection <Items>()
                                            {
                                                new Items()
                                                {
                                                    Name = "Craft Personnel7", ID = 9, ParentID = 8
                                                },
                                            },
                                        },
                                    },
                                },
                            },
                        },
                        new Items()
                        {
                            Name = "Administrative Officer", ID = 10, ParentID = 1
                        },
                        new Items()
                        {
                            Name = "Maintenance Manager", ID = 11, ParentID = 1, SubItems = new ObservableCollection <Items>()
                            {
                                new Items()
                                {
                                    Name = "Electrical Supervisor", ID = 12, ParentID = 11, SubItems = new ObservableCollection <Items>()
                                    {
                                        new Items()
                                        {
                                            Name = "Craft Personnel1", ID = 13, ParentID = 12
                                        },
                                        new Items()
                                        {
                                            Name = "Craft Personnel2", ID = 14, ParentID = 12
                                        },
                                    },
                                },
                                new Items()
                                {
                                    Name = "Mechanical Supervisor", ID = 15, ParentID = 11, SubItems = new ObservableCollection <Items>()
                                    {
                                        new Items()
                                        {
                                            Name = "Craft Personnel3", ID = 16, ParentID = 15
                                        },
                                        new Items()
                                        {
                                            Name = "Craft Personnel4", ID = 17, ParentID = 15
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };

            DefaultConnectorType = ConnectorType.Orthogonal;

            PageSettings = new PageSettings()
            {
                PageBackground  = new SolidColorBrush(Colors.Transparent),
                PageBorderBrush = new SolidColorBrush(Colors.Transparent),
            };

            SelectedItems = new SelectorViewModel()
            {
                SelectorConstraints = SelectorConstraints.Default & ~SelectorConstraints.QuickCommands & ~SelectorConstraints.Rotator & ~SelectorConstraints.Tooltip & ~SelectorConstraints.Pivot,
            };

            LayoutManager = new Syncfusion.UI.Xaml.Diagram.Layout.LayoutManager()
            {
                Layout = new DirectedTreeLayout()
                {
                    HorizontalSpacing = 20,
                    VerticalSpacing   = 40,
                    Orientation       = TreeOrientation.TopToBottom,
                    Type = LayoutType.Hierarchical,
                },
                RefreshFrequency = RefreshFrequency.ArrangeParsing,
            };

            DataSourceSettings = new DataSourceSettings()
            {
                Id         = "ID",
                ParentId   = "ParentID",
                DataSource = GetData(Datas),
            };

            #endregion
        }