Featured Posts

The WPF Must-Grok List Robert A. Heinlein defined the word grok as: Grok means to understand so thoroughly that the observer becomes a part of the observed—to merge, blend, intermarry, lose identity...

Read more

Yes, Virginia, TextBlock.Text Will Support MultiBinding 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...

Read more

Why Are WPF Developers Trying to Kill Menus? Somewhere along the line, and I’m not motivated enough to research it, menus apparently became bad.  I don’t mean they ever stopped working or became unsuitable for the...

Read more

WPF: What it is and What it is not Even though WPF has been around for a number of years, there is still some confusion as to what WPF is and what it is not.  Here are a few items that come to mind: What...

Read more

using System.Windows; Rss

Yes, Virginia, TextBlock.Text Will Support MultiBinding

Posted on : 12-02-2009 | By : Christopher Estep | In : Pain Points

Tags: , ,

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=F3}”/>
<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:

TextPropertyError

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% [?]

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • DotNetKicks
  • StumbleUpon
  • LinkedIn
  • Facebook
  • TwitThis
  • del.icio.us
  • Print

Comments are closed.