private void OnUnderLineChanged(bool UnderLine)
        {
            if (UnderLine)
            {
                if (Decoration == null)
                {
                    Decoration = new TextDecorationCollection();
                    Decoration.Add(TextDecorations.Underline);
                }
                else
                {
                    Decoration = new TextDecorationCollection();
                    Decoration.Add(TextDecorations.Strikethrough);
                    Decoration.Add(TextDecorations.Underline);
                }
            }
            else
            {
                if (Decoration != null && Decoration.Contains(TextDecorations.Strikethrough[0]))
                {
                    Decoration = new TextDecorationCollection();
                    Decoration.Add(TextDecorations.Strikethrough);
                }
                else
                {
                    Decoration = null;
                }
            }

            this.SetTextDecorations();
        }
Example #2
0
            static bool Compare(TextDecorationCollection cmp1, TextDecorationCollection cmp2)
            {
                if (cmp1 == null && cmp2 == null)
                {
                    return(true);
                }
                else if (cmp1 == null || cmp2 == null)
                {
                    return(false);
                }
                else if (cmp1.Count != cmp2.Count)
                {
                    return(false);
                }

                foreach (var i in cmp1)
                {
                    if (!cmp2.Contains(i))
                    {
                        return(false);
                    }
                }

                return(true);
            }
Example #3
0
 private static bool CompareTextDecorations(TextDecorationCollection firstTextDecorationCollection, TextDecorationCollection secondTextDecorationCollection)
 {
     if (firstTextDecorationCollection.Count != secondTextDecorationCollection.Count)
     {
         return(false);
     }
     foreach (TextDecoration textDecoration in firstTextDecorationCollection)
     {
         if (!secondTextDecorationCollection.Contains(textDecoration))
         {
             return(false);
         }
     }
     foreach (TextDecoration textDecoration in secondTextDecorationCollection)
     {
         if (!firstTextDecorationCollection.Contains(textDecoration))
         {
             return(false);
         }
     }
     return(true);
 }
Example #4
0
        private static bool CheckTextDecoration(RichTextBox rtf, TextDecoration decoration)
        {
            var       caret     = rtf.CaretPosition;
            Paragraph paragraph = FindBlock <Paragraph>(rtf.Document.Blocks, caret);

            if (paragraph != null)
            {
                Inline inline = paragraph.Inlines.FirstOrDefault(x => x.ContentStart.CompareTo(caret) <= 0 && x.ContentEnd.CompareTo(caret) >= 0) as Inline;
                if (inline != null)
                {
                    TextDecorationCollection decorations = inline.TextDecorations;
                    if (decorations == DependencyProperty.UnsetValue)
                    {
                        return(false);
                    }
                    else
                    {
                        return(decorations != null && decorations.Contains(decoration));
                    }
                }
            }

            return(false);
        }
        /// <summary>
        /// 设置为已经确认
        /// </summary>
        private void SetCheck()
        {
            //if ((FontWeight)RichTextBox1.Selection.GetPropertyValue(TextElement.FontWeightProperty) == FontWeights.Bold)
            //    RichTextBox1.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal);
            //else
            //    RichTextBox1.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);


            //var decorations = (TextDecorationCollection)RichTextBox1.Selection.GetPropertyValue(Inline.TextDecorationsProperty);
            //bool hasUnderline = decorations.Contains(TextDecorations.Strikethrough[0]);
            //if (hasUnderline)
            //    RichTextBox1.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, FontWeights.Normal);
            //else
            //    RichTextBox1.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Strikethrough);



            var selection = this.RichTextBox1.Selection;

            if (!selection.IsEmpty)
            {
                TextDecorationCollection tdc = selection.GetPropertyValue(Inline.TextDecorationsProperty) as TextDecorationCollection;
                if (tdc == null || !(tdc.SequenceEqual(TextDecorations.Strikethrough) || tdc.Contains(TextDecorations.Strikethrough[0])))
                {
                    selection.ApplyPropertyValue(Run.TextDecorationsProperty, TextDecorations.Strikethrough);
                }
                else
                {
                    selection.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
                }
            }
            else
            {
                //RichTextBox1.CaretPosition.InsertTextInRun("aaa");

                //RichTextBox1.Selection.Text = "百度";
                //TextRange tr = new TextRange(RichTextBox1.Selection.Start, RichTextBox1.Selection.End);
                //Hyperlink hlink = new Hyperlink(tr.Start, tr.End);
                //hlink.NavigateUri = new Uri("");


                var textRange = new TextRange(this.RichTextBox1.Document.ContentStart, this.RichTextBox1.Document.ContentEnd);
                if (!textRange.IsEmpty)
                {
                    textRange.ApplyPropertyValue(Inline.TextDecorationsProperty, null);
                }
            }
        }