【问题标题】:Wpf slider center tick valueWpf 滑块中心刻度值
【发布时间】:2014-01-24 20:49:51
【问题描述】:

我有一个滑块,其最小值为 -127,最大值为 127。启动时滑块位于中间,因此值为 0。 是否可以在刻度处显示文本 0,以便您可以明显地看到中心在哪里?

<Slider Margin="3"
            Minimum="-127"
            Maximum="127"
            TickPlacement="BottomRight"
            TickFrequency="2"
            IsSnapToTickEnabled="True"
            SmallChange="1" />

这是我的滑块的图片。

【问题讨论】:

    标签: wpf slider


    【解决方案1】:

    我认为单独使用滑块没有办法,我会尝试:

    <StackPanel HorizontalAlignment="Center">
        <Slider Grid.Row="2" Margin="3" Width="150"
            Minimum="-127"
            Maximum="127"
            TickPlacement="BottomRight"
            TickFrequency="2"
            IsSnapToTickEnabled="True"
            SmallChange="1" />
        <TextBlock Text="0" HorizontalAlignment="Center" Margin="0,-5,0,0"/>
    </StackPanel>
    

    编辑:我刚刚意识到你对此并不陌生,所以你一定想到了这个微不足道的解决方案......

    【讨论】:

      【解决方案2】:

      这就是我得到我想要的东西的方式。我在 Slider 下使用了 DockPanel 来布局 TextBlocks。 一个为中心0,一个在右侧设置最大值,另一个在左侧设置最小值。

      我找不到任何其他解决方案可以满足我的要求。如果有,请在此处发布:)

      XAML:

      <StackPanel Orientation="Vertical">
          <Slider x:Name="SpeedSlider"
                          Margin="3"
                          Foreground="DarkGray"
                          Value="{Binding SliderValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                          Maximum="{Binding Steps,
                                                          Mode=TwoWay,
                                                          UpdateSourceTrigger=PropertyChanged}"
                          Minimum="{Binding MinSteps,
                                                          Mode=TwoWay,
                                                          UpdateSourceTrigger=PropertyChanged}"
                          SmallChange="2"
                          TickFrequency="4"
                          TickPlacement="BottomRight"
                          ToolTip="{Binding ElementName=SpeedSlider,Path=Value}">
          </Slider>
          <DockPanel>
              <TextBox DockPanel.Dock="Left"
                               Text="{Binding MinSteps,
                                                          Mode=TwoWay,
                                                          UpdateSourceTrigger=PropertyChanged}"
                               Width="100"
                               Background="Transparent"
                               IsReadOnly="True"
                               BorderThickness="0" />
              <TextBox DockPanel.Dock="Right"
                               Text="{Binding Steps,
                                                          Mode=TwoWay,
                                                          UpdateSourceTrigger=PropertyChanged}"
                               Width="100"
                               HorizontalContentAlignment="Right"
                               Background="Transparent"
                               IsReadOnly="True"
                               BorderThickness="0" />
              <TextBlock DockPanel.Dock="Right"
                                   Text="0"
                                   HorizontalAlignment="Center" />
          </DockPanel>
      </StackPanel>
      

      图片:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-30
        • 2019-05-15
        • 2014-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多