One of my WPF Disciple buddies just sent an email around asking about Binding.StringFormat. Mmm so now there is a Binding.StringFormat. Neat. So we can now do things like the following. If you want to see all the new stuff in the .NET 3.5 BETA, check out Scott Guthries blog, using this link .NET 3.5 SP 1


   1:      <Grid>
   2:          <TextBlock Text="{Binding ElementName=slider1,
   3:              Path=Value, SringFormat='Amount: {0:0.000}'}"
   4:              Height="21" Margin="44,37,65,0"
   5:              VerticalAlignment="Top" />
   7:          <Slider Value="58″ Margin="53,77,50,0"
   8:              Name="slider1" Height="24"
   9:              VerticalAlignment="Top"
  10:              Maximum="100" />
  11:      </Grid>

.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }


10 thoughts on “Binding.StringFormat

  1. […] After I posted this, I saw that Sacha also posted about it here Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it! Published […]

  2. Fabrice says:

    Another great use of StringFormat is with a MultiBinding:

  3. Fabrice says:

    Hum… It looks like your blog doesn’t like XML.
    Is the following better?

    [MultiBinding StringFormat=”Customer {0} has {1} orders”]
    [Binding Path=”Customer.Name”/]
    [Binding Path=”Customer.Orders.Count”/]

  4. Fabrice says:

    Well, it doesn’t like indentation either! But you should get the point anyway.

  5. sacha says:

    why not post an example here Fabrice, that would be cool

  6. sacha says:

    Ah I see you did, cool

  7. sacha says:

    Thanks fabrice

  8. […] additions in .NET 3.5 SP1 is a StringFormat parameter you can pass along with your bindings. Sacha Barber has an example of how to use […]

  9. sacha says:

    Hey Paul,

    Thanks for the comment and congrats again on your excellent BindableLINQ (I have used some of your stuff in past, like Validation control that uses IDataErrorInfo)

    You do some cool stuff man, I think I use it over at codeproject, in this article if you are interested.

    I have a few 3D WPF ones that you may also like being a WPF man

    Have a look thourgh my articles see if any take your fancy

  10. greedstevenr says:

    juicy german english boy watch key all jhon cube look this house

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: