Exemple #1
0
        /// <summary>
        /// 刷新与指定元素连接的连线
        /// </summary>
        /// <param name="p_elem"></param>
        /// <returns></returns>
        internal void RefreshLinkLines(FrameworkElement p_elem)
        {
            SNode node = p_elem as SNode;

            if (node != null)
            {
                var lines = from obj in _container.Children
                            let item = obj as SLine
                                       where item != null && (item.HeaderID == node.ID || item.TailID == node.ID)
                                       select item;
                foreach (var line in lines)
                {
                    line.Refresh();
                }
            }
        }
Exemple #2
0
        static void OnFlagChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            SNode node = (SNode)d;
            Icons flag = (Icons)e.NewValue;

            if (flag == Icons.None)
            {
                node.FlagShape = null;
            }
            else
            {
                var shape = Res.GetIcon(flag, 20, Res.WhiteBrush);
                shape.IsHitTestVisible = false;
                node.FlagShape         = shape;
            }
            if (flag != Icons.None || (Icons)e.OldValue != Icons.None)
            {
                node.SavePropertyChange(e);
            }
        }
Exemple #3
0
        /// <summary>
        /// 拖拽(连接点公共部分处理)
        /// </summary>
        /// <param name="p_thumb">点实例</param>
        internal bool LinkThumbMove(Thumb p_thumb)
        {
            Rect  rect  = new Rect(Canvas.GetLeft(p_thumb), Canvas.GetTop(p_thumb), p_thumb.ActualWidth, p_thumb.ActualHeight);
            SNode taget = GetFirstIntersect(rect);

            if (taget != null)
            {
                VisualStateManager.GoToState(p_thumb, "DragValid", true);
                //设置目标
                _linkPrompt.Width  = taget.Width;
                _linkPrompt.Height = taget.Height;
                Canvas.SetLeft(_linkPrompt, Canvas.GetLeft(taget));
                Canvas.SetTop(_linkPrompt, Canvas.GetTop(taget));
                _linkPrompt.Visibility = Visibility.Visible;
                _linkPrompt.SetValidPos(GetLinkPosition(taget, rect));
                return(true);
            }
            else
            {
                _linkPrompt.Visibility = Visibility.Collapsed;
                return(false);
            }
        }
Exemple #4
0
        /// <summary>
        /// 加载xml字符串
        /// </summary>
        /// <param name="p_xml"></param>
        public void ReadXml(string p_xml)
        {
            _his?.Clear();
            _container.Children.Clear();
            _selectionClerk.Clear();

            if (string.IsNullOrEmpty(p_xml))
            {
                return;
            }

            using (StringReader stream = new StringReader(p_xml))
                using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings()
                {
                    IgnoreWhitespace = true, IgnoreComments = true, IgnoreProcessingInstructions = true
                }))
                {
                    reader.Read();

                    Rect totalRect = new Rect();
                    bool isFirst   = true;
                    reader.Read();
                    while (reader.NodeType != XmlNodeType.None)
                    {
                        if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Sketch")
                        {
                            break;
                        }

                        Rect   rc   = new Rect();
                        string name = reader.Name;
                        if (name == "Node")
                        {
                            SNode node = new SNode(this);
                            _container.Children.Add(node);
                            node.ReadXml(reader);
                            rc = new Rect(Canvas.GetLeft(node), Canvas.GetTop(node), node.Width, node.Height);
                        }
                        else if (name == "Line")
                        {
                            SLine line = new SLine(this);
                            _container.Children.Add(line);
                            line.ReadXml(reader);
                            rc = line.Bounds;
                        }
                        else if (name == "Txt")
                        {
                            TextBlock tb = new TextBlock();
                            _container.Children.Add(tb);
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.Name)
                                {
                                case "text": tb.Text = reader.Value; break;

                                case "fontsize": tb.FontSize = double.Parse(reader.Value); break;

                                    // uwp和手机系统weight的操作方式不同
#if UWP
                                case "fontweight": tb.FontWeight = new FontWeight()
                                {
                                        Weight = ushort.Parse(reader.Value)
                                }; break;
#else
                                case "fontweight": tb.FontWeight = new FontWeight(ushort.Parse(reader.Value)); break;
#endif
                                case "foreground": tb.Foreground = new SolidColorBrush(Res.HexStringToColor(reader.Value)); break;

                                case "fontstyle": tb.FontStyle = (FontStyle)int.Parse(reader.Value); break;

                                case "fontfamily": tb.FontFamily = new FontFamily(reader.Value); break;

                                case "left": Canvas.SetLeft(tb, double.Parse(reader.Value)); break;

                                case "top": Canvas.SetTop(tb, double.Parse(reader.Value)); break;

                                case "width": tb.Width = double.Parse(reader.Value); break;

                                case "height": tb.Height = double.Parse(reader.Value); break;
                                }
                            }
                            rc = new Rect(Canvas.GetLeft(tb), Canvas.GetTop(tb), tb.Width, tb.Height);
                        }

                        if (isFirst)
                        {
                            totalRect = rc;
                            isFirst   = false;
                        }
                        else
                        {
                            totalRect = Union(totalRect, rc);
                        }

                        reader.Read();
                    }

                    if (IsReadOnly)
                    {
                        ResizeReadOnlyPage(totalRect);
                    }
                    else
                    {
                        ResizeEditPage(totalRect);
                    }
                }
            RefreshAllLines();
        }