翻转滚动条 WPF

发布于 2024-10-01 06:50:50 字数 132 浏览 5 评论 0原文

你好 我正在构建一个显示从 0 到最大值的标尺的控件。 0 值位于底部,最大值位于高于 0 的 y 值(最大值在我们滚动到它之前不可见)。 问题是,当0向下时,最大值向上。滚动条的0值向上,最大值向下。 我希望滚动条能够翻转。 我怎样才能做到这一点?

Hi
I am building a control that shows a ruler from 0 to a maximum. The 0 value is at the bottom and the maximum is in a higher y then the 0(The maximum is not visible until we scroll to it).
The problem is that while 0 is down and the maximum is up. The 0 value of the scroll bar is up and the maximum is down.
I want that the scroll bar will be flipped.
How can I do that ?

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

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

发布评论

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

评论(3

月寒剑心 2024-10-08 06:50:50

伙计们,想简单一点:

            <ScrollBar.RenderTransform>
                <RotateTransform Angle="180"/>
            </ScrollBar.RenderTransform>

问候

Dudes, think simple:

            <ScrollBar.RenderTransform>
                <RotateTransform Angle="180"/>
            </ScrollBar.RenderTransform>

Regards

烟─花易冷 2024-10-08 06:50:50

如何使用值转换器来否定“最小值”、“最大值”和“值”属性。这样滚动条就会像你翻转它一样。

代码:

class NegativeValueConverter : IValueConverter
{
  object Convert(object value, ...)
  {
    return -System.Convert.ToDouble(value);
  }

  object ConvertBack(object value, ...)
  {
    return -System.Convert.ToDouble(value);
  }
}

xaml:

<Resources>
  <local:NegativeValueConverter x:Key="negative" />
</Resources>
<ScrollBar Value="{Binding RulerValue, Converter={StaticResource negative}"
           Minimum="{Binding RulerMinimum, Converter={StaticResource negative}"
           Maximum="{Binding RulerMaximum, Converter={StaticResource negative}"/>

How about using a value converter to negate your Minimum, Maximum and Value properties. That way the scrollbar will act as though you flipped it.

code:

class NegativeValueConverter : IValueConverter
{
  object Convert(object value, ...)
  {
    return -System.Convert.ToDouble(value);
  }

  object ConvertBack(object value, ...)
  {
    return -System.Convert.ToDouble(value);
  }
}

xaml:

<Resources>
  <local:NegativeValueConverter x:Key="negative" />
</Resources>
<ScrollBar Value="{Binding RulerValue, Converter={StaticResource negative}"
           Minimum="{Binding RulerMinimum, Converter={StaticResource negative}"
           Maximum="{Binding RulerMaximum, Converter={StaticResource negative}"/>
荒人说梦 2024-10-08 06:50:50

我受到这里一些答案的启发,并决定添加我的答案以供进一步参考。

对于滚动条来说,是否旋转 180 度或上下翻转并不重要,但对于其他控件(或某些样式)来说可能很重要。

这是我的代码:

<ScrollBar Orientation="Vertical" RenderTransformOrigin="0.5,0.5">
    <ScrollBar.RenderTransform>
        <ScaleTransform ScaleY="-1"/>
    </ScrollBar.RenderTransform>
</ScrollBar>

I got inspired by some answers here and decided to add mine for further reference.

For the scrollbar it doesn't really matter whether it is rotated 180 degrees or flipped upside down but for other controls (or some style) it may be important.

Here's my code:

<ScrollBar Orientation="Vertical" RenderTransformOrigin="0.5,0.5">
    <ScrollBar.RenderTransform>
        <ScaleTransform ScaleY="-1"/>
    </ScrollBar.RenderTransform>
</ScrollBar>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文