Binding.StringFormat

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" />
   6:  
   7:          <Slider Value="58″ Margin="53,77,50,0"
   8:              Name="slider1" Height="24"
   9:              VerticalAlignment="Top"
  10:              Maximum="100" />
  11:      </Grid>

9 Comments so far »

  1. Using Binding.StringFormat - Rudi Grobler said

    am May 16 2008 @ 7:02 pm

    [...] 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 said

    am May 22 2008 @ 12:22 am

    Another great use of StringFormat is with a MultiBinding:

  3. Fabrice said

    am May 22 2008 @ 12:25 am

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

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

  4. Fabrice said

    am May 22 2008 @ 12:25 am

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

  5. sacha said

    am May 22 2008 @ 6:51 am

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

  6. sacha said

    am May 22 2008 @ 6:52 am

    Ah I see you did, cool

  7. sacha said

    am May 22 2008 @ 6:53 am

    Thanks fabrice

  8. Paul Stovell says… » We don’t need no String.Format binding! said

    am June 3 2008 @ 8:53 am

    [...] 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 said

    am June 3 2008 @ 9:02 am

    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

    http://www.codeproject.com/KB/WPF/PhysicsFun.aspx 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

    http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=569009

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: