Search code examples
silverlighttextblockinlineuicontainer

Silverlight InlineCollection.Add(InlineUIContainer) missing?


I'm having difficulty adding the inline of specific type InlineUIContainer into the InlineCollection (Content property) of a TextBlock. It appears the .Add() method of InlineCollection doesn't accept this type, however you can clearly set it through XAML without explicitly marking the content as a InlineContainer, as demonstrated in many examples:

http://msdn.microsoft.com/en-us/library/system.windows.documents.inlineuicontainer.aspx

Is it possible to programatically add one of these as in the following?

Target.Inlines.Add(new Run() { Text = "Test" });
Target.Inlines.Add(new InlineUIContainer() { 
Child = new Image() { Source = new BitmapImage(new Uri("http://example.com/someimage.jpg")) } });
Target.Inlines.Add(new Run() { Text = "TestEnd" });

I have a feeling what's going on is that Silverlight is using a value converter to create the runs when specified in XAML as in the example which doesn't use InlineContainer, but I'm not sure where to look to find out.

The specific error I'm getting is as follows:

Cannot add value of type 'System.Windows.Documents.InlineUIContainer' to a 'InlineCollection' in a 'System.Windows.Controls.TextBlock'.

Solution

  • As pointed out by Jedidja, we need to use RichTextBox to do this in Silverlight.