I cannot get my DataBinding to cut off the decimal digits of my sliders double value and add a % sign. I want that my view only displays "89%" even if the sliders value is 89.1234. Is it possible to use stringFormat in WPF DataBinding to realize that behavior?
<Label Content="{Binding ElementName=Slider, Path=Value}"/>
Thank you very much in advance for any help.
You cannot use the Binding's StringFormat
if you are also using a Label
because the Label
has a property called ContentStringFormat
that overrides the binding's StringFormat
Either use the Label's ContentStringFormat
property
<Label Content="{Binding ElementName=Slider, Path=Value}"
ContentStringFormat="{}{0:N0}%" />
Or switch to using a TextBlock
<TextBlock Text="{Binding ElementName=Slider, Path=Value, StringFormat={}{0:N0}%}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With