Search code examples
c#wpfdata-bindingtextboxslider

How to WPF slider value make sure the numbers be shown to the thousandths?


I have TextBox of binded Slider value and I want make sure the numbers be shown to the thousandths.

How do I get it?

<Slider x:Name="AOch1" 
        Maximum="20" 
        Minimum="4" 
        Value="4" 
        Width="250" 
        BorderThickness="5" 
        TickPlacement="BottomRight"
        Margin="0 -20 0 0" 
        ValueChanged="AOch1_ValueChanged"/>

<TextBox Width="70" 
         Height="20" 
         Grid.Row="1" 
         Margin="0 0 80 180" 
         x:Name="AO1text"
         Text="{Binding ElementName=AOch1,Path=Value}"/>

Solution

  • Try this:

    Text="{Binding ElementName=AOch1,Path=Value, StringFormat={}{0:F3}}"