在ListView列中对齐Slider和TextBlock

时间:2015-07-02 09:26:15

标签: wpf listview slider

我有ListView,我在同一个Slider中插入了TextBlockcolumn

<DataTemplate x:Key="MyDataTemplate2">
    <Grid Margin="-7" >
        <Slider Name="sliderColumn"
                HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource SliderStyle}" Width="80"/>
        <TextBlock Text="{Binding Path=Value, ElementName=sliderColumn, StringFormat={}{0}}" FontSize="11" Foreground="White"
                   VerticalAlignment="Center" HorizontalAlignment="Right" />
    </Grid>
</DataTemplate>

这就是结果:

enter image description here

Slider值发生变化时,它变得不可读:

enter image description here

有任何建议如何修复它并确保只显示整数?

1 个答案:

答案 0 :(得分:1)

通过在滑块TickFrequencyIsSnapToTickEnabled

中添加这两个属性来更改滑块
<Slider Name="sliderColumn"
            HorizontalAlignment="Left" VerticalAlignment="Center" Width="80" TickFrequency="1" IsSnapToTickEnabled="True"/>