滑块和标签值绑定未四舍五入

时间:2019-03-16 12:07:21

标签: visual-studio xaml

我一直在努力获取标签以正确显示滑块的值。我将StringFormat添加到第一个标签中,以防止出现诸如1.00000000000001之类的值,但它们仍会显示出来,我不知道为什么。任何帮助表示赞赏!

    <Slider x:Name="speedSlider" HorizontalAlignment="Left" Margin="126,43,0,0" VerticalAlignment="Top" Height="26" Width="250" Minimum="0.5" IsSnapToTickEnabled="True" TickFrequency="0.1"/>
    <Slider x:Name="sizeSlider" HorizontalAlignment="Left" Margin="126,89,0,0" VerticalAlignment="Top" Width="250" Minimum="10" Maximum="20" IsSnapToTickEnabled="True" TickFrequency="2"/>
    <Label x:Name="speedLabel" Content="Speed cm/s" HorizontalAlignment="Left" Margin="44,43,0,0" VerticalAlignment="Top"/>
    <Label x:Name="sizeLabel" Content="Size in pixels" HorizontalAlignment="Left" Margin="44,81,0,0" VerticalAlignment="Top"/>
    <Label x:Name="speedSliderNumberLabel" Content="{Binding ElementName=speedSlider, Path=Value, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:0.00}}" HorizontalAlignment="Left" Margin="381,43,0,0" VerticalAlignment="Top"/>
    <Label x:Name="sizeSliderNumberLabel" Content="{Binding ElementName=sizeSlider,Path=Value, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="381,81,0,0" VerticalAlignment="Top"/>

0 个答案:

没有答案