0

I have a slider and I want to display his value on the ToolTip.

As slider's Value property is a double, ToolTip display like "12.12548565". I just want to display a rounded value ("12")

I've tried :

<Slider x:Name="sldAnalogSetPoint"
        Maximum="100"
        ValueChanged="sldAnalogSetPoint_ValueChanged"
        Cursor="Arrow"
        ToolTip="{Binding Value, ElementName=sldAnalogSetPoint, StringFormat=/{0:D/}}"/>

what's wrong ?

F.Berne
  • 3
  • 2
  • See [this tutorial](http://www.wpf-tutorial.com/data-binding/the-stringformat-property/) or the [MSDN page on formatting strings](https://msdn.microsoft.com/en-us/library/26etazsy(v=vs.110).aspx) – ChrisF Dec 02 '16 at 13:22
  • 1
    The Binding's StringFormat is ignored, because the type of the target property (ToolTip) isn't string. – Clemens Dec 02 '16 at 13:38

1 Answers1

-2

Use IsSnapToTickEnabled and TickFrequency properties fo slider:

How do you make a WPF slider snap only to discrete integer positions?

ToolTip:

ToolTip="{Binding Value, ElementName=sldAnalogSetPoint}"

<Slider ... IsSnapToTickEnabled="True" TickFrequency="1"/>

You can also use Converter(https://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(v=vs.110).aspx) for your binding. But that will be bad solution.

Community
  • 1
  • 1
Uladzimir Sharyi
  • 144
  • 1
  • 14