This question is locked. New answers and comments are not allowed.
I have a requirement where I need to switch an icon that I have inserted using the inlineuicontainer to text. Currently a user inserts what we are calling a note. An icon is inserted at the cursor position to show that there is a note at this position. Mousing over this icon displays the notes value. Now what I am trying to do is to have a button that would toggle every note that is in the document to hide the inlineiocontainer and to show the notes text value. I currently have this working but the text is not showing up where I would expect it to. I seem to be doing something wrong with the position because I can set the position when the note is inserted and then when I call ShowText the position is changed and it inserts everything in one location.
public void InsertAnnotation(string GUID, String noteText)
{
string url = "/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/FindNextSpellingError.png";
Image annotationIcon = new Image();
annotationIcon.Source = new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute));
CustomHyperLinkButton link = new CustomHyperLinkButton { Width = 20, Height = 20, Content = annotationIcon, Name = "Note_" + GUID, NoteContent = noteText, };
DocumentPosition position = new DocumentPosition(editor.Document);
position = editor.Document.CaretPosition;
link.LocationInDoc = position;
link.showingText = false;
TextBox textBox = new TextBox { Width = 295, Height = 345, Text = noteText, TextWrapping = TextWrapping.Wrap};
RadWindow radWindow = new RadWindow {Width = 300, Height = 300, Header = "Note", Content = textBox, Visibility = Visibility.Visible };
ToolTipService.SetToolTip(link, radWindow);
link.Click += AnnotationLinkButton_Click;
InlineUIContainer container = new InlineUIContainer
{
UiElement = link,
Width = 20,
Height = 20d,
};
editor.InsertInline(container);
position.Reset();
}
private void ShowText(object sender, RoutedEventArgs e)
{
List<
InlineUIContainer
> links = editor.Document.EnumerateChildrenOfType<
InlineUIContainer
>().ToList();
foreach (var inlineUiContainer in links)
{
CustomHyperLinkButton btn = (CustomHyperLinkButton) inlineUiContainer.UiElement;
if (!btn.showingText)
{
btn.Visibility = Visibility.Collapsed;
Span span = new Span("{ " + btn.NoteContent + " }");
editor.Document.InsertInline(span, btn.LocationInDoc);
btn.showingText = true;
}
}
}