Setting the Scrollbar Thumb size

后端 未结 5 1270
醉梦人生
醉梦人生 2021-02-05 17:01

I am attempting to work out the algorithm associated with sizing of the WPF Scrollbar thumb element.

The thumb element can be sized using the Scrollbar.ViewportSi

5条回答
  •  自闭症患者
    2021-02-05 17:15

    Scrollbar thumb size for UWP:

        static void SetViewportSize(ScrollBar bar, double size)
        {
            var max = (bar.Maximum - bar.Minimum);
            bar.ViewportSize = size / (max - size) * max;
            bar.IsEnabled = (bar.ViewportSize >= 0 &&
                bar.ViewportSize != double.PositiveInfinity);
            InvalidateScrollBar(bar);
        }
    
        static void InvalidateScrollBar(ScrollBar bar)
        {
            var v = bar.Value;
            bar.Value = (bar.Value == bar.Maximum) ? bar.Minimum : bar.Maximum;
            bar.Value = v;
        }
    

提交回复
热议问题