Matt McManis
Matt McManis

Reputation: 4675

Limit Slider TextBox Decimal Places

I have a Slider and Value TextBox.

enter image description here

It gives a value with 14 decimal places.

How can I limit (not round) the amount of decimals to 2? 75.89

Limit it in the textbox, not process it after. And not snap to tick.

<Slider x:Name="slVolume" 
        HorizontalAlignment="Right"
        Margin="0,92,48,0" 
        VerticalAlignment="Top" 
        Width="66"
        Maximum="100" 
        />

<TextBox x:Name="tbxVolume"
         Text="{Binding ElementName=slVolume, Path=Value, UpdateSourceTrigger=PropertyChanged}"
         Width="29" 
         Height="22" 
         TextWrapping="Wrap" 
         Margin="0,91,14,0" 
         HorizontalAlignment="Right" 
         VerticalAlignment="Top"/>

Upvotes: 5

Views: 2233

Answers (1)

ASh
ASh

Reputation: 35646

add StringFormat to Text binding:

Text="{Binding ElementName=slVolume, Path=Value, StringFormat=N2, UpdateSourceTrigger=PropertyChanged}"

Upvotes: 5

Related Questions