I have a label bound to the value of a slider.
Content="{Binding Path=Value, ElementName=Slider}"
How do I append a percentage symbol? The value of the slider is already formatted correctly, so when the value is '50', all I need is '50%'.
I know how to do it in code behind but I was hoping to accomplish this in xaml without creating a converter. TIA
I had a similar issue and solved it by using this, based on @Wiesel's answer:
<Label Content="{Binding Value, ElementName=Slider}"
ContentStringFormat="{}{0}%"/>
This works fine for me (tested in Kaxaml):
<StackPanel>
<Slider Minimum="0" Maximum="100" x:Name="slider" />
<TextBlock Text="{Binding Path=Value, ElementName=slider, StringFormat='\{0\}%'}" />
</StackPanel>
Without the backslashes I got an error saying that the % character was invalid in that position.
StringFormat can be used in this format as well
Content="{Binding Path=Value, ElementName=Slider, StringFormat=P2}"
You can use StringFormat like so
Content="{Binding Path=Value, ElementName=Slider, StringFormat='{0}%'}"
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