views:

86

answers:

1

I've binded the tooltip of a slider control to it's Value property and i'm trying to use StringFormat to make it display "Current Value {0} of 10" where the {0} is the Value property. Below is one of the various things I tried when trying to figure this out.

                 <Slider.ToolTip>
                    <Label>
                        <Label.Content>
                            <Binding StringFormat="Current Value {0} of 10" ElementName="DebugLevelSlider" Path="Value"/>
                        </Label.Content>
                    </Label>
                </Slider.ToolTip>

I am having issues finding examples online of how to use stringformat with string literals such as mine above. I see a lot of stringformat date/time/currency format conversion. I think I have a way to do this with a multibinding but it just seems like an extra amount of work than necessary. I hope that for string literal formatting I still do not have to write a custom converter.

In my app I find myself using a lot of extra labels next to items so getting an understanding in the stringformat will hopefully let me eliminate some of those unnecessary labels.

+3  A: 

For the ToolTip, you can check out http://stackoverflow.com/questions/197095/wpf-binding-with-stringformat-doesnt-work-on-tooltips.

As far as the StringFormat you specified above, you have to escape your string.

StringFormat="{}Current Value {0} of 10"

Here are a bunch of StringFormat examples. http://blogs.msdn.com/b/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx

a_hardin
I still can't get the binding to work on the Value property of my slider but it works when I bind the tooltip to the variable that the slider is bound to. Maybe Value isn't a bindable slider property..hmm
TWood