Formatted text inside TextBlock / TextBox - with binding

This may have been asked before, but I'm really looking for an easy way to display software formatted text inside some text container. For decoupling purposes, I would like to use the binding property, this is how I am doing it now:

<TextBlock Height="219" Name="_txtBox" Text="{Binding myText}" />

and then

myText = "<TextBlock>\n <Run FontWeight=\"Bold\">\n" + item1 + "\n</Run>\n " + item2 + "\n</TextBlock>";

For some design reasons unknown to WP7, this will not work, I also tried TextBox. Is there a way so that I can output some kind of small formatted text to any control without undue complication?

I would like to keep the binding in place

+3
source share
1 answer

. , , . .

XAML

<TextBlock x:Name="text1" ></TextBlock>

    InlineCollection inlines = text1.Inlines;
    Run r = new Run();
    r.Text = "item 1";
    r.FontWeight = FontWeights.Bold;
    inlines.Add(r);
    inlines.Add(new LineBreak());
    r = new Run();
    r.Text = "item 2";
    inlines.Add(r);
+4

All Articles