如何设置 wpf 滑块控件拇指的高度

发布于 2024-09-16 12:57:21 字数 233 浏览 2 评论 0原文

我想在数据网格单元格中放置一个滑块,并且该行的高度为 20,因此我想让滑块的拇指高度小于该高度。我设置了滑块本身的高度,但拇指似乎被切断了(即它没有缩小到我在 slider.height 属性中指定的高度)。我不想必须重写滑块控件的整个控件模板才能执行此操作。必须有某种方法来设置属性或类似的东西。

编辑:即使当我创建一个自定义滑块样式(其中包括具有我想要的尺寸的自定义拇指样式)时,它的尺寸仍然不正确。

有什么想法吗?

I want to put a slider in a datagrid cell and the row has a height of 20, so i'd like to make the height of the thumb of the slider smaller than that. I set the height of the slider itself, but the thumb appears to be cut off (i.e. it doesn't scale down to the height that I specify in the slider.height property). I don't want to have to override the entire control template of the slider control to do this. There's got to be some way of setting a property or something like that.

Edit: Even when I create a custom slider style which includes the custom thumb style with the sizes I want, it still doesn't size right.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风铃鹿 2024-09-23 12:57:21
<Slider.LayoutTransform>
    <ScaleTransform ScaleY="0.9" CenterX="15" CenterY="15"/>
</Slider.LayoutTransform>

不是很性感,但是当与 Slider.Height/Slider.Width 属性结合使用时,它就像一个魅力!

<Slider.LayoutTransform>
    <ScaleTransform ScaleY="0.9" CenterX="15" CenterY="15"/>
</Slider.LayoutTransform>

Not very sexy, but it works like a charm when combined whith the Slider.Height/Slider.Width properties !

贪了杯 2024-09-23 12:57:21

设置拇指样式:

<Style x:Key="SliderThumbStyle" TargetType="{x:Type Thumb}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
                <!--<Ellipse 
                      Name="Ellipse" 
                      Fill="Yellow"
                      Stroke="Yellow" 
                      Height="10"
                      Width="{Binding Path=ThumbWidth, RelativeSource={RelativeSource TemplatedParent}}"
                      StrokeThickness="1" />-->
                <Rectangle 
                    Fill="Azure"
                    Stroke="Azure"
                    Height="7"
                    Width="{Binding Path=ThumbWidth, RelativeSource={RelativeSource TemplatedParent}}"
                    StrokeThickness="1"
                    Margin="0.1,.1,.1,.1"/>

            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

然后使用此样式滑块自定义控件

<Style TargetType="{x:Type local:NvSliderControl}">
    <Setter Property="Orientation" Value="Vertical" />
    <Setter Property="Height" Value="50"/>        
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:NvSliderControl}">
                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid>
                        <Track x:Name="PART_Track" >
                            <Track.Thumb>
                                <Thumb Style="{StaticResource SliderThumbStyle}">
                                </Thumb>
                            </Track.Thumb>
                        </Track>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Set thumb style:

<Style x:Key="SliderThumbStyle" TargetType="{x:Type Thumb}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
                <!--<Ellipse 
                      Name="Ellipse" 
                      Fill="Yellow"
                      Stroke="Yellow" 
                      Height="10"
                      Width="{Binding Path=ThumbWidth, RelativeSource={RelativeSource TemplatedParent}}"
                      StrokeThickness="1" />-->
                <Rectangle 
                    Fill="Azure"
                    Stroke="Azure"
                    Height="7"
                    Width="{Binding Path=ThumbWidth, RelativeSource={RelativeSource TemplatedParent}}"
                    StrokeThickness="1"
                    Margin="0.1,.1,.1,.1"/>

            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Then use this style slider custom control

<Style TargetType="{x:Type local:NvSliderControl}">
    <Setter Property="Orientation" Value="Vertical" />
    <Setter Property="Height" Value="50"/>        
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:NvSliderControl}">
                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid>
                        <Track x:Name="PART_Track" >
                            <Track.Thumb>
                                <Thumb Style="{StaticResource SliderThumbStyle}">
                                </Thumb>
                            </Track.Thumb>
                        </Track>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文