Search code examples
wpfgeometryshapestextblockstring.format

WPF: 2 string.format in the same TextBlock?


I have a Circle slider and inside this Slider i put TextBlock that shows the Slider value, I also use String.Format to present the value in int instead of double:

<TextBlock Text="{Binding Path=Value, ElementName=knobSlider, StringFormat={}{0:#,#}}" Foreground="White"
           FontFamily="Trebuchet MS" FontSize="25" HorizontalAlignment="Center"
           VerticalAlignment="Center" />

Now want to add before the Slider value a specific character for example '*', so is it possible to user another string.format ?


Solution

  • No need for another StringFormat - if you're trying to add characters before the value, you just need to replace the double curly braces with your text. I think this is what you're trying to achieve:

    <TextBlock HorizontalAlignment="Center"
            VerticalAlignment="Center"
            FontFamily="Trebuchet MS"
            FontSize="25"
            Foreground="White"
            Text="{Binding Path=Value,
                            ElementName=knobSlider,
                            StringFormat=\*{0:#,#}}" />