예제 #1
0
        private void Ele_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ForceNodeControl control = sender as ForceNodeControl;

            //System.Diagnostics.Debug.WriteLine($"{control.ActualWidth}, {control.ActualHeight}");

            viewModel.FixedItem = control.Node;
            if (fixedButton.IsChecked == false)
            {
                fixedButton.IsChecked = true;
            }
            else
            {
                viewModel.Excute();
            }
        }
예제 #2
0
        private void loadComponents()
        {
            mark.SetBinding(Canvas.LeftProperty, new Binding
            {
                Path = new PropertyPath("Cx"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Converter           = xyConverter,
                ConverterParameter  = new ControlXy {
                    Control = mark, Target = "Width"
                }
            });
            mark.SetBinding(Canvas.TopProperty, new Binding
            {
                Path = new PropertyPath("Cy"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Converter           = xyConverter,
                ConverterParameter  = new ControlXy {
                    Control = mark, Target = "Height"
                }
            });

            foreach (var item in viewModel.Links)
            {
                var line = new Line();
                line.DataContext     = item;
                line.ToolTip         = item.Relationship.ToString();
                line.StrokeThickness = 1.5;
                switch (item.Relationship)
                {
                case Model.Relationship.Realization:
                    line.Stroke = Brushes.Red;
                    break;

                case Model.Relationship.Generalization:
                    line.Stroke = Brushes.Orange;
                    break;

                case Model.Relationship.Association:
                    line.Stroke = Brushes.Yellow;
                    break;

                case Model.Relationship.Aggregation:
                    line.Stroke = Brushes.Green;
                    break;

                case Model.Relationship.Composition:
                    line.Stroke = Brushes.Blue;
                    break;

                case Model.Relationship.Dependency:
                    line.Stroke = Brushes.Purple;
                    break;

                default:
                    line.Stroke = Brushes.Gray;
                    break;
                }
                line.SetBinding(Line.X1Property, new Binding {
                    Path = new PropertyPath("Source.X")
                });
                line.SetBinding(Line.X2Property, new Binding {
                    Path = new PropertyPath("Target.X")
                });
                line.SetBinding(Line.Y1Property, new Binding {
                    Path = new PropertyPath("Source.Y")
                });
                line.SetBinding(Line.Y2Property, new Binding {
                    Path = new PropertyPath("Target.Y")
                });
                canvas.Children.Add(line);

                //var block = new TextBlock();
                //block.DataContext = item;
                //block.FontSize = 9; block.FontFamily = new FontFamily("consloas");
                //block.SetBinding(TextBlock.TextProperty, new Binding { Path = new PropertyPath("Relationship") });
                //block.SetBinding(Canvas.LeftProperty, new Binding
                //{
                //    Path = new PropertyPath("MiddleX"),
                //    Converter = xyConverter,
                //    ConverterParameter = new ControlXy { Control = block, Target = "X" }
                //});
                //block.SetBinding(Canvas.TopProperty, new Binding
                //{
                //    Path = new PropertyPath("MiddleY"),
                //    Converter = xyConverter,
                //    ConverterParameter = new ControlXy { Control = block, Target = "Y" }
                //});
                //canvas.Children.Add(block);
            }

            var nodes = viewModel.Nodes;

            for (int i = nodes.Count - 1; i > -1; i--)
            {
                var item             = nodes[i];
                ForceNodeControl ele = new ForceNodeControl();
                ele.Node = item;

                //ele.Width = ele.Height = shapeWidth;

                ele.SetBinding(Canvas.LeftProperty, new Binding
                {
                    Path               = new PropertyPath("X"),
                    Converter          = xyConverter,
                    ConverterParameter = new ControlXy {
                        Control = ele, Target = "X"
                    }
                });
                ele.SetBinding(Canvas.TopProperty, new Binding
                {
                    Path               = new PropertyPath("Y"),
                    Converter          = xyConverter,
                    ConverterParameter = new ControlXy {
                        Control = ele, Target = "Y"
                    }
                });
                ele.MouseDoubleClick += Ele_MouseDoubleClick;

                this.canvas.Children.Add(ele);
            }
        }