Beispiel #1
0
        public int CompareTo(object obj)
        {
            RichTextTag p = obj as RichTextTag;

            if (Metadata == p.Metadata)
            {
                return(string.Compare(StyleID, p.StyleID));
            }
            else
            {
                return(1);
            }
        }
Beispiel #2
0
        public void ApplyStyle(RichTextBoxStyle style, RichTextBoxStyle linkStyle, bool useLinkButtons)
        {
            RichTextTag tag    = new RichTextTag();
            bool        isLink = false;

            this.IsHitTestVisible = false;

            if (this.Tag is RichTextTag)
            {
                tag = (RichTextTag)this.Tag;
                if (tag.Metadata != null)
                {
                    isLink = tag.Metadata.IsLink;
                }

                if (useLinkButtons)
                {
                    if (isLink)
                    {
                        if (_link == null)
                        {
                            Children.Remove(_element);
                            _element.Foreground = new SolidColorBrush(Colors.Red);

                            _link = new HyperlinkButton()
                            {
                                Content     = _element,
                                NavigateUri = new Uri(tag.Metadata["URL"]),
                                TargetName  = (tag.Metadata.ContainsKey("Target") ? tag.Metadata["Target"] : "_blank")
                            };
                            Children.Insert(0, _link);
                        }
                        this.IsHitTestVisible = true;
                    }
                    else
                    {
                        if (_link != null)
                        {
                            Children.Remove(_link);
                            _link = null;
                            Children.Insert(0, _element);
                        }
                    }
                }
            }

            _element.FontFamily      = new FontFamily(style.Family);
            _element.FontSize        = (style.Size != null ? (double)style.Size : 14);
            base.Background          = style.Background;
            _element.Foreground      = isLink ? linkStyle.Foreground : style.Foreground;
            _element.FontWeight      = (style.Weight != null ? (FontWeight)style.Weight : FontWeights.Normal);
            _element.FontStyle       = (style.Style != null ? (FontStyle)style.Style : FontStyles.Normal);
            _element.TextDecorations = isLink ? linkStyle.Decorations : style.Decorations;
            _effect       = style.Effect;
            _border       = style.BorderType;
            _shadowEffect = style.Shadow;

            HorizontalAlignment = style.Alignment;
            VerticalAlignment   = style.VerticalAlignment;

            if (style.ShadowBrush != null)
            {
                _shadowBrush = style.ShadowBrush;
            }

            if (style.Special == RichTextSpecialFormatting.Subscript)
            {
                _element.FontSize   *= RichTextBlock.SubScriptMultiplier;
                VerticalAlignment    = VerticalAlignment.Bottom;
                LineHeightMultiplier = 1 / RichTextBlock.SubScriptMultiplier;
            }
            else if (style.Special == RichTextSpecialFormatting.Superscript)
            {
                _element.FontSize   *= RichTextBlock.SuperScriptMultiplier;
                VerticalAlignment    = VerticalAlignment.Top;
                LineHeightMultiplier = 1 / RichTextBlock.SuperScriptMultiplier;
            }
            else
            {
                LineHeightMultiplier = 1;
            }

            Margin = new Thickness(style.Margin.Left, style.Margin.Top, style.Margin.Right, style.Margin.Bottom);

            UpdateStyle();
        }