예제 #1
0
        public DialogHyperlink(RichTextBox textBox)
        {
            this.textBox = textBox;
            Hyperlink link = DialogHyperlink.SelectedHyperlink(this.textBox);

            if (link != null)
            {
                TextRange range = new TextRange(link.ContentStart, link.ContentEnd);
                this.HyperlinkText = range.Text;
                this.HyperlinkUrl  = link.NavigateUri.ToString();
                textBox.Selection.Select(link.ElementStart, link.ElementEnd);
            }
            else
            {
                this.HyperlinkText = this.textBox.Selection.Text;
                string text = this.HyperlinkText.Trim();
                if (DialogHyperlink.IsUrl(text))
                {
                    this.HyperlinkUrl = text;
                }
                else
                {
                    this.HyperlinkUrl = string.Empty;
                }
            }
            this.DataContext = this;
            this.InitializeComponent();
        }
예제 #2
0
 private static Hyperlink SelectedHyperlink(RichTextBox textBox)
 {
     if (textBox.Selection.IsEmpty)
     {
         return(DialogHyperlink.SelectedHyperlink(textBox.Selection.Start));
     }
     else
     {
         Hyperlink h1 = DialogHyperlink.SelectedHyperlink(textBox.Selection.Start);
         Hyperlink h2 = DialogHyperlink.SelectedHyperlink(textBox.Selection.End);
         if (h1 == h2 && h1 != null)
         {
             return(h1);
         }
         if (h1 != null)
         {
             return(h1);
         }
         if (h2 != null)
         {
             return(h2);
         }
         h1 = DialogHyperlink.FindHyperlink(textBox.Selection.Start, LogicalDirection.Forward);
         h2 = DialogHyperlink.FindHyperlink(textBox.Selection.End, LogicalDirection.Backward);
         if (h1 == h2)
         {
             return(h1);
         }
     }
     return(null);
 }
예제 #3
0
        private static Hyperlink FindHyperlink(TextPointer textPointer, LogicalDirection logicalDirection)
        {
            TextPointer tp = textPointer.GetNextInsertionPosition(logicalDirection);

            if (tp != null)
            {
                return(DialogHyperlink.SelectedHyperlink(tp));
            }
            return(null);
        }