flip scrollbar WPF

前提是你 提交于 2019-12-14 03:39:37

问题


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 ?


回答1:


Dudes, think simple:

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

Regards




回答2:


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}"/>



回答3:


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>


来源:https://stackoverflow.com/questions/4139263/flip-scrollbar-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!