示例#1
0
        /// <summary>
        /// Create the node ports
        /// </summary>
        /// <param name="node1">Node</param>
        /// <param name="id">Port ID</param>
        /// <param name="nodeoffsetx">Node offset-x value.</param>
        /// <param name="nodeoffsety">Node offset-y value.</param>
        private void CreateNodePort(CustomNodeViewModel node1, string id, double nodeoffsetx, double nodeoffsety)
        {
            NodePortViewModel nodePort = new NodePortViewModel()
            {
                ID          = id,
                NodeOffsetX = nodeoffsetx,
                NodeOffsetY = nodeoffsety,
            };

            (node1.Ports as PortCollection).Add(nodePort);
        }
示例#2
0
        /// <summary>
        /// Create and return the node.
        /// </summary>
        /// <param name="offsetx">offset-x of the node</param>
        /// <param name="offsety">offset-y of the node.</param>
        /// <param name="height">Height of the node</param>
        /// <param name="text">Text annotation of the node</param>
        /// <returns></returns>
        private CustomNodeViewModel CreateNodes(double offsetx, double offsety, double height, string text)
        {
            CustomNodeViewModel node = new CustomNodeViewModel()
            {
                UnitHeight  = height,
                UnitWidth   = 100,
                OffsetX     = offsetx,
                OffsetY     = offsety,
                Shape       = App.Current.Resources["RoundedRectangle"],
                Fill        = new SolidColorBrush(Colors.White),
                Annotations = new ObservableCollection <IAnnotation>()
                {
                    new TextAnnotationViewModel()
                    {
                        Text       = text,
                        FontSize   = 13,
                        Foreground = new SolidColorBrush(Colors.Black),
                        FontFamily = new FontFamily("Calibri(Body)"),
                    }
                },
            };

            return(node);
        }
示例#3
0
        /// <summary>
        /// Created the new instances of the <see cref="ConnectorsViewModel"/> class.
        /// </summary>
        public ConnectorsViewModel()
        {
            //Initialize the nodes and connectors collection
            this.Nodes      = new ObservableCollection <CustomNodeViewModel>();
            this.Connectors = new ObservableCollection <CustomConnectorViewModel>();

            //Initialize the port visibility as collapse
            this.PortVisibility = PortVisibility.Collapse;

            //Initialize the default connector type.
            this.DefaultConnectorType = ConnectorType.CubicBezier;

            //Enable the routing to the connectors.
            this.Constraints |= GraphConstraints.Routing;

            //Initialize the horizontal and vertical ruler.
            this.HorizontalRuler = new Ruler()
            {
                Orientation = Orientation.Horizontal,
            };
            this.VerticalRuler = new Ruler()
            {
                Orientation = Orientation.Vertical,
            };
            //Initialize the snap settings.
            this.SnapSettings = new SnapSettings()
            {
                SnapConstraints = SnapConstraints.ShowLines,
            };

            //Initialize the shape selection command.
            SelectShapeCommand = new Command(OnSelectShapeCommandExecute);

            //Initialize the item added command.
            ItemAddedCommand = new Command(OnItemAddedCommandExecute);

            //Initialize the view port chnaged command.
            ViewPortChangedCommand = new Command(OnViewPortChangedCommandExecute);

            //Create and add nodes
            CustomNodeViewModel promotion   = CreateNodes(140, 350, 30, "Promotion");
            CustomNodeViewModel lead        = CreateNodes(300, 350, 70, "Lead");
            CustomNodeViewModel account     = CreateNodes(500, 270, 30, "Account");
            CustomNodeViewModel information = CreateNodes(500, 350, 30, "Information");
            CustomNodeViewModel opportunity = CreateNodes(500, 430, 30, "Opportunity");
            CustomNodeViewModel template    = CreateNodes(700, 350, 204, "");

            template.ContentTemplate = App.Current.Resources["ContentTemplateforNodeContent"] as DataTemplate;

            //Create node ports
            CreateNodePort(promotion, "promotion", 1, 0.5);

            CreateNodePort(lead, "lead1", 0, 0.5);
            CreateNodePort(lead, "lead2", 1, 0.5);
            CreateNodePort(lead, "lead3", 1, 0.75);
            CreateNodePort(lead, "lead4", 1, 0.25);

            CreateNodePort(information, "information1", 0, 0.5);
            CreateNodePort(information, "information2", 1, 0.5);

            CreateNodePort(account, "account1", 0, 0.5);
            CreateNodePort(account, "account2", 1, 0.5);

            CreateNodePort(opportunity, "opportunity1", 0, 0.5);
            CreateNodePort(opportunity, "opportunity2", 1, 0.5);

            CreateNodePort(template, "template1", 0, 0.5);
            CreateNodePort(template, "template2", 0, 0.4);
            CreateNodePort(template, "template3", 0, 0.6);

            //Add nodes to Nodes property of the Diagram
            (this.Nodes as ObservableCollection <CustomNodeViewModel>).Add(promotion);
            (this.Nodes as ObservableCollection <CustomNodeViewModel>).Add(lead);
            (this.Nodes as ObservableCollection <CustomNodeViewModel>).Add(account);
            (this.Nodes as ObservableCollection <CustomNodeViewModel>).Add(information);
            (this.Nodes as ObservableCollection <CustomNodeViewModel>).Add(opportunity);
            (this.Nodes as ObservableCollection <CustomNodeViewModel>).Add(template);

            //Create and add connectors
            CreateConnectors("promotion", "lead1");
            CreateConnectors("lead4", "account1");
            CreateConnectors("lead2", "information1");
            CreateConnectors("lead3", "opportunity1");
            CreateConnectors("template2", "account2");
            CreateConnectors("template1", "information2");
            CreateConnectors("template3", "opportunity2");
            this.CreateDecoraorsCollection();

            this.SelectedItems = new SelectorViewModel();
            (this.SelectedItems as SelectorViewModel).SelectorConstraints &= ~(SelectorConstraints.QuickCommands);
        }