WPF: Cannot Combine Bindings and Other Text

It is not a big deal, but still unpleasant. It is not possible to do something like

<TextBlock Text=”Speed: {Binding Path=Speed} mph” />

The text in the squiggles appears verbatim on screen, the binding does not occur. Instead, one needs to write

<TextBlock>Speed: <TextBlock Text=”{Binding Path=Speed}” /> mph</TextBlock>

This requires significant amount of extra typing when writing, and creates serious clutter when reading. Not a big deal, but disappointing. A better solution would be to parse expressions like this and do the bindings. Of course, there will be implications: if one really wants a squiggle, they will have to escape it, just like in String.Format. Also, when looking for bindings and other extensions, WPF will have to scan the whole text instead of just checking the first character. I am not sure how serious this is, but it does not sound very ominous. I suspect WPF authors just did not have time to implement this advanced parsing.

Leave a Reply

Your email address will not be published. Required fields are marked *