ScrollViewer default to HorizontalScrollBarVisibility and VerticalScrollBarVisibility values

17. September 2010

 

If you check the WPF(as well as Silverlight) ScrollViewer's default values for HorizontalScrollBarVisibility (Disabled) and VerticalScrollBarVisibility (Visible). 

I was curious to know Why does the ScrollViewer default to HorizontalScrollBarVisibility Disabled and VerticalScrollBarVisibility Visible, and found this page which explains the reason.

"For compatibility with the WPF defaults, of course. :) Regarding the obvious next question about why those values are the WPF defaults, I don't know. Auto/Auto would seem more generally useful to me and, in fact, the WPF ListBox (and Silverlight ListBox) overrides the ScrollViewer defaults to set Auto/Auto! But maintaining compatibility wins, so the Silverlight ScrollViewer defaults to the same values used by WPF."

 

In most of our application we need HorizontalScrollBarVisibility and VerticalScrollBarVisibility to be Auto by default. To achieve this behaviour, we can add teh following style in your applications style.

 

<Style TargetType="{x:Type ScrollViewer}">

            <Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>

            <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>

      </Style>

 

 

.Net Tips, Technical, wpf , , ,

blog comments powered by Disqus