Lester's WPF\SL Blog

Simple, Easy & Beautiful

WPF 3.5 SP1 feature: StringFormat

WPF 3.5 SP1 feature: StringFormat

Rate This
  • Comments 20

One of the new features in 3.5 SP1 is stringformat. The usage is pretty simple. So following are simple snippets showing its use

<TextBox Text="{Binding Path=Double, StringFormat=F3}"/>

<TextBox Text="{Binding Path=Double, StringFormat=Amount: {0:C}}"/>

<TextBox Text="{Binding Path=Double, StringFormat=Amount: \{0:C\}}"/>



    <Binding Path="Double" StringFormat="{}{0:C}"/>






    <MultiBinding StringFormat="{}{0:F2} = {1:D}">

      <Binding Path="Double" />

      <Binding Path="Date"/>






    <Binding Path="Date" StringFormat="{}{0:MM/dd/yyyy}"/>



<ListBox Background="Beige" ItemStringFormat="F3">




<GroupBox Background="AliceBlue" Content="{Binding Path=Double}" ContentStringFormat="F4"

          Header="{Binding Path=Double}" HeaderStringFormat="F5"/>

<Label Content="{Binding Path=Double}" ContentStringFormat="{}{0:E2}"/>


  <GridViewColumn Header="Date"

           DisplayMemberBinding="{Binding XPath=Date, StringFormat=D}" />

 This feature makes life a lot more easier when it comes to formatting.. So have fun with it.

Share this post


  • Hi!

    I like the string.format feature. But there is one problem:

    If the value you are binding to is null the formated string will show


    I would expect it to show simply nothing.

    Will that be fixed in the final release?

  • Endelig! En af de nye features der kommer med WPF 3.5 SP1 er StringFormat. Lester har skrevet en fin

  • Apologies for the sparseness of my posting the last few weeks - work and life have been busy here lately

  • I wrote some postings about data binding in the past (see here , here and here ). It is a pretty cool

  • Via this post . I won&#39;t elaborate so much about it, do read Lester&#39;s post in the link above.

Page 2 of 2 (20 items) 12