Yes, Virginia, TextBlock.Text Will Support MultiBinding
Posted on : 02-12-2009 | By : Christopher Estep | In : Pain Points
Tags: Binding, Bugs, Text
0
One of the features introduced to WPF in version 3.5 SP1 is the StringFormat property.
If you’re unaware, StringFormat allows you to bring the String.Format capability to WPF binding and is particularly useful in MultiBinding scenarios. If you search through the internet, you’ll see many examples of people using TextBox.Text and TextBlock.Text with MultiBinding, such as:
<TextBox Text=”{Binding Path=Double, StringFormat=Amount: {0:C}}“/>
<TextBox Text=”{Binding Path=Double, StringFormat=Amount: \\cf2 {0:C\\cf2 }}”/>
<TextBox>
<TextBox.Text>
<Binding Path=”Double” StringFormat=”{}{0:C}”/>
</TextBox.Text>
</TextBox>
It’s all good, right? Well, guess what happens when you try to use similar code in Visual Studio:
Oh No! Right?
Wrong!
It turns out that in spite of the error, the code works just fine. Needless to say, I’ll be reporting this bug. But until it’s fixed, it’s wise to remember that you can’t always trust inline syntax checking and to do your homework before deciding to abandon a proven technique.
Popularity: 17% [?]

