views:

21

answers:

1

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.

+1  A: 

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.

HTH,
Kent

Kent Boogaart
Thanks, Kent. I'm using 3.5. Any alternative suggestions?
Chris
Binding a `TextBlock` to the Variable part and use `StringFormat`. Needs SP1.
Kent Boogaart
That's it, thanks.
Chris