View unanswered posts | View active topics It is currently 2020-05-26 6:41



This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
 设置Node节点背景是文字而非图片填充 
Author Message
新手上路

Joined: 2014-06-04 9:24
Posts: 3
Post 设置Node节点背景是文字而非图片填充
我是亿阳信通股份有限公司,咨询问题如下:
现在有个需求是:
设定一个Node节点需要显示两个文本,一个文本是在节点下方 ,另一个文本显示是在节点本身(这两处文本不同)
节点下方设定的文本方式是: Node.Name= 名字
节点本身文本怎么显示? (背景填充一个纯色就行了,不需要图片)

具体看一下附件。


Attachments:
123.png
123.png [ 14.01 KiB | Viewed 6742 times ]
2014-06-04 9:39
Profile
TWaver开发组
User avatar

Joined: 2009-04-20 18:37
Posts: 3115
Post Re: 设置Node节点背景是文字而非图片填充
LabelNode
Code:
using TWaver;
using System.Windows.Media;

namespace Demo
{
    class LabelNode : Node
    {
        public LabelNode()
            : base()
        {
            this.Init();
        }

        public LabelNode(object id)
            : base(id)
        {
            this.Init();
        }

        private void Init()
        {
            this.SetStyle(Styles.CONTENT_TYPE, Consts.CONTENT_TYPE_VECTOR);
            this.SetStyle(Styles.VECTOR_GRADIENT, null);
            this.SetStyle(Styles.VECTOR_SHAPE, Consts.SHAPE_CIRCLE);
            this.SetStyle(Styles.VECTOR_FILL_COLOR, Colors.White);
            this.SetStyle(Styles.VECTOR_OUTLINE_COLOR, Colors.Black);
            this.SetStyle(Styles.VECTOR_OUTLINE_WIDTH, 1);
        }

        public override System.Type ElementUIClass
        {
            get
            {
                return typeof(LabelNodeUI);
            }
        }
    }
}



LabelNodeUI
Code:
using TWaver;
using TWaver.Network;
using TWaver.Network.UI;

namespace Demo
{
    class LabelNodeUI: NodeUI
    {
        private BodyLabelAttachment labelAttachment = null;

        public LabelNodeUI(Network network, Node node)
            : base(network, node)
        {
        }

        public override void CheckAttachments()
        {
            base.CheckAttachments();
            this.CheckBodyLabelAttachment();
        }

        private void CheckBodyLabelAttachment()
        {
            string label = element.GetClient<string>("text");
            if (label != null && label != string.Empty)
            {
                if (this.labelAttachment == null)
                {
                    this.labelAttachment = new BodyLabelAttachment(this);
                    this.AddAttachment(this.labelAttachment);
                }
            }
            else
            {
                if (this.labelAttachment != null)
                {
                    this.RemoveAttachment(this.labelAttachment);
                    this.labelAttachment = null;
                }
            }
        }
    }
}


BodyLabelAttachment:
Code:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using TWaver;
using TWaver.Network.UI;

namespace Demo
{
    class BodyLabelAttachment : LabelAttachment
    {
        private TextBlock textBlock = new TextBlock();

        public BodyLabelAttachment(ElementUI elementUI)
            : base(elementUI)
        {
            this.Content = textBlock;
        }

        protected override void UpdateContent()
        {
            textBlock.FontFamily = Element.GetStyle<FontFamily>(Styles.LABEL_FONT);
            textBlock.FontSize = Element.GetStyle<double>(Styles.LABEL_SIZE);
            textBlock.FontStyle = Element.GetStyle<bool>(Styles.LABEL_ITALIC) ? FontStyles.Italic : FontStyles.Normal;
            textBlock.FontWeight = Element.GetStyle<bool>(Styles.LABEL_BOLD) ? FontWeights.Bold : FontWeights.Normal;
            textBlock.TextDecorations = Element.GetStyle<bool>(Styles.LABEL_UNDERLINE) ? TextDecorations.Underline : null;
            textBlock.Foreground = new SolidColorBrush(Element.GetStyle<Color>(Styles.LABEL_COLOR));

            string text = element.GetClient<string>("text");
            textBlock.Text = (text == null || text == string.Empty) ? " " : text;
        }

        public override string Position
        {
            get { return Consts.POSITION_CENTER; }
        }
    }
}

用法:
Code:
            LabelNode node = new LabelNode();
            node.SetClient("text", "test");
            node.Name = "Name";
            network.ElementBox.Add(node);

效果:


Attachments:
Screen Shot 2014-06-04 at 2.58.35 pm.png
Screen Shot 2014-06-04 at 2.58.35 pm.png [ 8.38 KiB | Viewed 6722 times ]
2014-06-04 14:50
Profile
新手上路

Joined: 2014-06-04 9:24
Posts: 3
Post Re: 设置Node节点背景是文字而非图片填充
谢谢,perfect~


2014-06-04 15:21
Profile
Display posts from previous:  Sort by  
This topic is locked, you cannot edit posts or make further replies.   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron