Sunday, August 26, 2012

RichTextBox editor determine if selection is image

RichTextBox editor determine if selection is image

I have an editor similar to the one described here:

http://msdn.microsoft.com/en-us/library/ff426926(v=vs.95).aspx

I am trying to determine if the user's selection in the rtb is an image so they can edit the properties without deleting it and re-adding it.

I have already implemented this feature for a hyperlink with this code:

private void RichTextBoxEditor_SelectionChanged(object sender, RoutedEventArgs e)          {              Inline parent = this.RichTextBoxEditor.Selection.Start.Parent as Inline;              if (parent != null)              {                  Hyperlink hyperlink = parent.ElementStart.Parent as Hyperlink;                  if (hyperlink == null)                  {                      this.tbUrlEditor.Visibility = Visibility.Collapsed;                  }                  else                  {                      this.tbUrlEditor.Visibility = Visibility.Visible;                      this.tbUrlEditor.Text = hyperlink.NavigateUri.ToString();                  }              }            }

So, when the user's caret or selection is a hyperlink, they are able to edit its Uri in my TextBox "tbUrlEditor".

I am hoping to be able to do the same thing with an image, but I am not successful when I try the same approach.

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog