开发者

How do I set the height of a wpf slider control's thumb

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 开发者_如何学Gothat.

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?


<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 !


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜