Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding the content of a Span

I have a window that displays text. There are two parts to the text: the first is fixed while the second needs to be the content of a DependencyProperty declared on the window.

I considered using a TextBlock containing two Spans, the first of which contains the fixed content and the second of which contains the variable content, but I can't see anything obvious on the Span class that would allow me to bind to the aforementioned DependencyProperty.

I'm currently using two Labels stacked side by side but this is ugly and doesn't help me if I wish to retrieve the content of the entire text block (as I do when displaying a ToolTip in the event that the window is too narrow to display the entire text block).

Can anyone help me to crack this seemingly simple problem? Thanks.

like image 677
Chris Ward Avatar asked Jul 28 '10 18:07

Chris Ward


1 Answers

If you're using .NET 4:

<TextBlock>
    <Run Text="Fixed:"/>
    <Run Text="{Binding Variable}"/>
</TextBlock>

Prior to .NET 4, the Run's Text property was not a dependency property.

like image 109
Kent Boogaart Avatar answered Oct 05 '22 09:10

Kent Boogaart