WPF ScrollBar:同一个模板中的水平和垂直滚动条?

发布于 2024-09-30 01:36:31 字数 446 浏览 1 评论 0原文

我需要重新模板化 ScrollBar,以便只需要一个 Template,而不是单独的水平和垂直模板。设计者的断言是 ScrollBar 可以在 Trigger 上旋转(方向 = 水平),并且可以在按钮上交换命令。

由于单个 Template 设置为包含行的 Grid,因此水平 ScrollBar 在旋转时会卡在视图的中心,仅显示左按钮和右按钮。这似乎是因为中心*行的高度是轨道区域的高度,所以它不会拉伸。在 Trigger 中绑定到父 ScrollViewer ActualWidth 之类的高度会导致通常的堆栈溢出。

有什么想法吗?我认为所有示例都有单独的水平和垂直模板是有原因的。

I have a requirement to retemplate the ScrollBar so that only one Template is required, instead of separate horizontal and vertical ones. The designer's assertion is that the ScrollBar can be rotated on a Trigger (Orientation = Horizontal), and the commands swapped on the buttons.

Since the single Template is set up as a Grid with rows, the horizontal ScrollBar is stuck in the center of the view when rotated, showing just the left and right buttons. This seems to be because the height of the center * row is the height of the track area, so it won't stretch. Binding in the Trigger to the height of something like the parent ScrollViewer ActualWidth causes the usual stackoverflow.

Any thoughts? I presume there's a reason all the examples have a horizontal and vertical templates separate.

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

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

发布评论

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

评论(1

把回忆走一遍 2024-10-07 01:36:31

没关系。我想通了:

            <Trigger Property="Orientation" Value="Horizontal">

            <!-- Rotate the ScrollBar from Vertical to Horizontal -->
            <Setter Property="LayoutTransform" TargetName="gLayoutRoot">
                <Setter.Value>
                    <RotateTransform Angle="90"/>
                </Setter.Value>
            </Setter>

            <!-- Change Track Orientation back to Vertical -->
            <Setter TargetName="PART_Track" Property="Orientation" Value="Vertical"/>
            <Setter TargetName="PART_Track" Property="IsDirectionReversed" Value="false"/>

            <!-- Change the commands to do Horizontal commands -->
            <Setter Property="Command" Value="ScrollBar.LineRightCommand" TargetName="DecreaseRepeat"/>
            <Setter Property="Command" Value="ScrollBar.LineLeftCommand" TargetName="IncreaseRepeat"/>
            <Setter Property="Command" Value="ScrollBar.PageLeftCommand" TargetName="PageDown"/>
            <Setter Property="Command" Value="ScrollBar.PageRightCommand" TargetName="PageUp"/>

        </Trigger>

然后在样式中将所有内容设置为“拉伸”或“自动”。

        <Setter Property="HorizontalAlignment" Value="Stretch"/> 
    <Setter Property="VerticalAlignment" Value="Stretch"/>
    <Setter Property="Width" Value="Auto"/> 
    <Setter Property="Height" Value="Auto"/>

幸运的是,其中一件事成功了。

Never mind. I figured it out:

            <Trigger Property="Orientation" Value="Horizontal">

            <!-- Rotate the ScrollBar from Vertical to Horizontal -->
            <Setter Property="LayoutTransform" TargetName="gLayoutRoot">
                <Setter.Value>
                    <RotateTransform Angle="90"/>
                </Setter.Value>
            </Setter>

            <!-- Change Track Orientation back to Vertical -->
            <Setter TargetName="PART_Track" Property="Orientation" Value="Vertical"/>
            <Setter TargetName="PART_Track" Property="IsDirectionReversed" Value="false"/>

            <!-- Change the commands to do Horizontal commands -->
            <Setter Property="Command" Value="ScrollBar.LineRightCommand" TargetName="DecreaseRepeat"/>
            <Setter Property="Command" Value="ScrollBar.LineLeftCommand" TargetName="IncreaseRepeat"/>
            <Setter Property="Command" Value="ScrollBar.PageLeftCommand" TargetName="PageDown"/>
            <Setter Property="Command" Value="ScrollBar.PageRightCommand" TargetName="PageUp"/>

        </Trigger>

Then in the style set everything to Stretch or Auto.

        <Setter Property="HorizontalAlignment" Value="Stretch"/> 
    <Setter Property="VerticalAlignment" Value="Stretch"/>
    <Setter Property="Width" Value="Auto"/> 
    <Setter Property="Height" Value="Auto"/>

Fortunately one of those things that worked out.

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