示例#1
0
        private void OnThemeStyleIdChanged()
        {
            var info = this.Info as INodeInfo;

            if (Constraints.Contains(NodeConstraints.ThemeStyle) && info != null && info.Graph.Theme != null)
            {
                if (!string.IsNullOrEmpty(ShapeName) && !ShapeName.Equals("Line"))
                {
                    DiagramItemStyle style = info.Graph.Theme.GetNodeStyle(ThemeStyleId);
                    if (style != null)
                    {
                        foreach (TextAnnotationViewModel annotaiton in (this.Annotations as AnnotationCollection))
                        {
                            annotaiton.Foreground = style.Foreground;
                            annotaiton.FontSize   = (int)style.FontSize;
                            annotaiton.FontFamily = style.FontFamily;
                        }
                    }
                }
            }
        }
示例#2
0
        protected override void OnPropertyChanged(string name)
        {
            base.OnPropertyChanged(name);
            switch (name)
            {
            case "ShapeStyle":
                DecodeStyle(this.ShapeStyle);
                break;

            case "Fill":
                ApplyStyle();
                break;

            case "Stroke":
                ApplyStyle();
                break;

            case "ThemeStyleId":

                if (!string.IsNullOrEmpty(ShapeName) && (ShapeName.Equals("Line") || ShapeName.Equals("Freehand")))
                {
                    TextAnnotationViewModel textAnnotaiton = Annotations != null ? (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel : null;
                    if (textAnnotaiton != null)
                    {
                        textAnnotaiton.Foreground = Brushes.Black;
                    }
                }
                if (this.Info != null && (this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0)
                {
                    Style connectorGeometryStyle = SetDefultConnectorGeometryStyle();
                    Style targetDecoratorStyle   = SetDefaultTargetDecoratorStyle();
                    foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList())
                    {
                        connector.ConnectorGeometryStyle = connectorGeometryStyle;
                        connector.TargetDecoratorStyle   = targetDecoratorStyle;
                    }
                }
                break;

            case "Children":
                Children.CollectionChanged += (s, e) =>
                {
                    if (Children.Count() > 0)
                    {
                        HasChidren = true;
                    }
                    else
                    {
                        HasChidren = false;
                    }
                };
                break;

            case "Annotations":
                if (Annotations != null)
                {
                    if (Annotations != null)
                    {
                        if ((Annotations as AnnotationCollection).Count > 0)
                        {
                            if ((Annotations as AnnotationCollection)[0] is TextAnnotationViewModel)
                            {
                                TextAnnotationViewModel textAnnotation = (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel;
                                textAnnotation.PropertyChanged += Annotation_PropertyChanged;
                            }
                        }
                        else
                        {
                            (Annotations as AnnotationCollection).CollectionChanged += (s, e) =>
                            {
                                if (e.NewItems != null && e.NewItems[0] is TextAnnotationViewModel)
                                {
                                    (e.NewItems[0] as TextAnnotationViewModel).EditTemplate     = GetEditTemplate();
                                    (e.NewItems[0] as TextAnnotationViewModel).PropertyChanged += Annotation_PropertyChanged;
                                }
                            };
                        }
                    }
                }
                //if (Annotations != null && (Annotations as AnnotationCollection).Count > 0)
                //{
                //    if ((Annotations as AnnotationCollection)[0] is TextAnnotationViewModel)
                //    {
                //        TextAnnotationViewModel textAnnotation = (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel;
                //        textAnnotation.PropertyChanged += Annotation_PropertyChanged;
                //    }
                //}
                break;

            case "ShapeName":
                TextAnnotationViewModel annotation = Annotations != null ? (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel : null;
                if (!string.IsNullOrEmpty(ShapeName) && ShapeName.Equals("Line"))
                {
                    Shape           = null;
                    ContentTemplate = GetLineTempalte();
                    Content         = this;
                    if (annotation != null)
                    {
                        annotation.TextVerticalAlignment = VerticalAlignment.Stretch;
                        annotation.Foreground            = Brushes.Black;
                    }
                    if (this.Ports != null)
                    {
                        if ((this.Info as INodeInfo).InConnectors != null && (this.Info as INodeInfo).InConnectors.Count() > 0)
                        {
                            foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList())
                            {
                                if (this.RenderedDirection == RootChildDirection.Left)
                                {
                                    connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[3];
                                }
                                else if (this.RenderedDirection == RootChildDirection.Right)
                                {
                                    connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[0];
                                }
                            }
                        }
                        if ((this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0)
                        {
                            foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList())
                            {
                                if (this.RenderedDirection == RootChildDirection.Left)
                                {
                                    connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[0];
                                }
                                else if (this.RenderedDirection == RootChildDirection.Right)
                                {
                                    connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[3];
                                }
                            }
                        }
                    }
                }
                else
                {
                    Shape           = GetShapeData(ShapeName);
                    ContentTemplate = null;
                    Content         = null;
                    if (annotation != null)
                    {
                        annotation.TextVerticalAlignment = VerticalAlignment.Center;
                        if (!string.IsNullOrEmpty(ShapeName) && ShapeName.Equals("Freehand"))
                        {
                            annotation.Foreground = Brushes.Black;
                        }
                        else
                        {
                            OnThemeStyleIdChanged();
                        }
                    }
                    if (!string.IsNullOrEmpty(ShapeName) && ShapeName.Equals("Wave"))
                    {
                        if (this.Ports != null && this.Info != null)
                        {
                            if ((this.Info as INodeInfo).InConnectors != null && (this.Info as INodeInfo).InConnectors.Count() > 0)
                            {
                                foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList())
                                {
                                    if (this.RenderedDirection == RootChildDirection.Left)
                                    {
                                        connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[2];
                                    }
                                    else if (this.RenderedDirection == RootChildDirection.Right)
                                    {
                                        connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[1];
                                    }
                                }
                            }
                            if ((this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0)
                            {
                                foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList())
                                {
                                    if (this.RenderedDirection == RootChildDirection.Left)
                                    {
                                        connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[1];
                                    }
                                    else
                                    {
                                        connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[2];
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (this.Info != null)
                        {
                            if ((this.Info as INodeInfo).InConnectors != null &&
                                (this.Info as INodeInfo).InConnectors.Count() > 0)
                            {
                                foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList())
                                {
                                    connector.TargetPort = null;
                                }
                            }
                            if ((this.Info as INodeInfo).OutConnectors != null &&
                                (this.Info as INodeInfo).OutConnectors.Count() > 0)
                            {
                                foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList())
                                {
                                    connector.SourcePort = null;
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
示例#3
0
 protected override void OnPropertyChanged(string name)
 {
     base.OnPropertyChanged(name);
     if (name.Equals("Annotations"))
     {
         //if (Annotations is List<IAnnotation> && (Annotations as AnnotationCollection).Count > 0
         //    && (Annotations as AnnotationCollection)[0] is TextAnnotationViewModel)
         //{
         //    TextAnnotationViewModel annotation = (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel;
         //    annotation.PropertyChanged += Annotation_PropertyChanged;
         //}
         if ((Annotations as List <IAnnotation>).Count > 0)
         {
             LabelVM annotation = (Annotations as List <IAnnotation>)[0] as LabelVM;
             annotation.PropertyChanged += Annotation_PropertyChanged;
         }
     }
     else if (name.Equals("ShapeName"))
     {
         LabelVM annotation = (Annotations as List <IAnnotation>)[0] as LabelVM;
         if (ShapeName.Equals("Line"))
         {
             Shape           = null;
             ContentTemplate = App.Current.Resources["LineShapeTemplate"] as DataTemplate;
             Content         = this;
             annotation.TextVerticalAlignment = VerticalAlignment.Stretch;
             annotation.LabelForeground       = Brushes.Black;
             if (this.Ports != null)
             {
                 if ((this.Info as INodeInfo).InConnectors != null && (this.Info as INodeInfo).InConnectors.Count() > 0)
                 {
                     foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList())
                     {
                         if (this.Type.Contains("left"))
                         {
                             connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[3];
                         }
                         else if (this.Type.Contains("right"))
                         {
                             connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[0];
                         }
                     }
                 }
                 if ((this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0)
                 {
                     foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList())
                     {
                         if (this.Type.Contains("left"))
                         {
                             connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[0];
                         }
                         else if (this.Type.Contains("right"))
                         {
                             connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[3];
                         }
                     }
                 }
             }
         }
         else
         {
             Shape           = App.Current.Resources[ShapeName];
             ContentTemplate = null;
             Content         = null;
             annotation.TextVerticalAlignment = VerticalAlignment.Center;
             if (ShapeName.Equals("Freehand"))
             {
                 annotation.LabelForeground = Brushes.Black;
             }
             else
             {
                 OnThemeStyleIdChanged();
             }
             if (ShapeName.Equals("Wave"))
             {
                 if (this.Ports != null)
                 {
                     if ((this.Info as INodeInfo).InConnectors != null && (this.Info as INodeInfo).InConnectors.Count() > 0)
                     {
                         foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList())
                         {
                             if (this.Type.Contains("left"))
                             {
                                 connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[2];
                             }
                             else if (this.Type.Contains("right"))
                             {
                                 connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[1];
                             }
                         }
                     }
                     if ((this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0)
                     {
                         foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList())
                         {
                             if (this.Type.Contains("left"))
                             {
                                 connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[1];
                             }
                             else
                             {
                                 connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[2];
                             }
                         }
                     }
                 }
             }
             else
             {
                 if (this.Info != null)
                 {
                     if ((this.Info as INodeInfo).InConnectors != null &&
                         (this.Info as INodeInfo).InConnectors.Count() > 0)
                     {
                         foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList())
                         {
                             connector.TargetPort = null;
                         }
                     }
                     if ((this.Info as INodeInfo).OutConnectors != null &&
                         (this.Info as INodeInfo).OutConnectors.Count() > 0)
                     {
                         foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList())
                         {
                             connector.SourcePort = null;
                         }
                     }
                 }
             }
         }
     }
 }