WPF自定义scrollview步骤 [英] WPF Custom scrollview steps

查看:68
本文介绍了WPF自定义scrollview步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在创建自定义滚动视图,但问题是步骤是标准高度,意味着如果您有500 px窗口高度和内容高度650 px高度滚动条不完全可用,但如果内容高度超过2000px滚动条也会移动
多。

Hello I'm creating custom scrollview, but the problem is that is steps work as standard heigh, means if you have 500 px window heigh and content height 650 px height scrollbar is not fully usable, but if content height is over 2000px scrollbar moves too much.

        <Style x:Key="ScrollBarTrackThumb" TargetType="{x:Type Thumb}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Grid x:Name="Grid" Height="19">
                            <Rectangle HorizontalAlignment="Stretch"/>
                            <Border x:Name="CornerScrollBarRectangle" CornerRadius="50" Margin="0,1,0,1" Background="{TemplateBinding Background}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="Tag" Value="Horizontal">
                                <Setter TargetName="CornerScrollBarRectangle" Property="Width"  Value="Auto" />
                                <Setter TargetName="CornerScrollBarRectangle" Property="Height" Value="0" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="{x:Type ScrollBar}">
            <Setter Property="Stylus.IsFlicksEnabled" Value="true" />
            <Setter Property="Foreground" Value="#ADABAB" />
            <Setter Property="Background" Value="{x:Null}" />
            <Setter Property="Width" Value="34" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ScrollBar}">
                        <Grid x:Name="GridRoot" Width="19" Background="{TemplateBinding Background}" Height="450">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.5*" />
                            </Grid.RowDefinitions>
                            <Rectangle VerticalAlignment="Stretch" Width="1" Margin="0,40" Stroke="Black"/>
                            <Track x:Name="PART_Track" IsDirectionReversed="true" Focusable="false">
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb" Background="{TemplateBinding Foreground}" Style="{DynamicResource ScrollBarTrackThumb}" Height="19" VerticalAlignment="Top" Margin="0,30,0,0" />
                                </Track.Thumb>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton x:Name="PageUp" Command="ScrollBar.PageDownCommand" Opacity="0" Focusable="false"/>
                                </Track.IncreaseRepeatButton>
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton x:Name="PageDown" Command="ScrollBar.PageUpCommand" Opacity="0" Focusable="false"/>
                                </Track.DecreaseRepeatButton>
                            </Track>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger SourceName="Thumb" Property="IsMouseOver" Value="true">
                                <Setter Value="{DynamicResource ButtonSelectBrush}" TargetName="Thumb" Property="Background" />
                            </Trigger>
                            <Trigger SourceName="Thumb" Property="IsDragging" Value="true">
                                <Setter Value="{DynamicResource DarkBrush}" TargetName="Thumb" Property="Background" />
                            </Trigger>

                            <Trigger Property="IsEnabled" Value="false">
                                <Setter TargetName="Thumb" Property="Visibility" Value="Visible" />
                            </Trigger>
                            <Trigger Property="Orientation" Value="Horizontal">
                                <Setter TargetName="GridRoot" Property="LayoutTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="-90" />
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="PART_Track" Property="LayoutTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="-90" />
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Width" Value="Auto" />
                                <Setter Property="Height" Value="1" />
                                <Setter TargetName="Thumb" Property="Tag" Value="Horizontal" />
                                <Setter TargetName="PageDown" Property="Command" Value="ScrollBar.PageLeftCommand" />
                                <Setter TargetName="PageUp" Property="Command" Value="ScrollBar.PageRightCommand" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

我相信此行负责的步骤 

I believe for steps this line is responsible 

<RowDefinition Height="0.5*" />

但更改它无济于事。

测试代码:

<Grid Background="#FFC50D0D">
        <ScrollViewer>
            <Grid Height="750">
                <Button Click="Button_Click" HorizontalAlignment="Center" VerticalAlignment="Center" Width="125" FontFamily="Tahoma" Height="44">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="108" >
                        <TextBlock Text="Hello"/>
                    </StackPanel>
                </Button>
            </Grid>
        </ScrollViewer>
    </Grid>

感谢您的帮助。

Thanks for help.

了解的图片:

正如您所见,scollbar位于中间位置,但内容位于底部。

As you can see scollbar is somewhere in middle, but content is in bottom.

推荐答案

仍在寻找修改滚动条步骤的方法。
Still looking for way to modify scrollbar steps.


这篇关于WPF自定义scrollview步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆