0

I want to change the width/height of the scrollbars (including the ones inside the datagrids and other controls) in all the application. I successfully tested and tweacked this solution which applies to ONE datagrid:

How to increase size of Datagrid Scrollbar?

<DataGrid.Resources>
    <Style TargetType="ScrollBar">
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="Width" Value="Auto"/>
                <Setter Property="Height" Value="50" />
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Width" Value="50"/>
                <Setter Property="Height" Value="Auto" />
            </Trigger>
        </Style.Triggers>                   
    </Style> 
</DataGrid.Resources>

But, how can I change the style of ALL the scrollbars and do it "application-wide"?

I suppose I should do it from Application.Resources but did'nt find any solution for that.

EDIT: Adding the scrollbar style in <Application.Resources> does not fully work as it does not changes the scrollbars inside other controls (like datagrids).

Adam Calvet Bohl
  • 1,009
  • 14
  • 29

1 Answers1

0

From what you require it seems that you need to change the styling of some ScrollBars only. And for this you need to somehow appoint which scrollbars to change ("all of them") and which not ("except DataGrids").

I'd do the following:

  • in your App.xaml (as already pointed out) define the style you want to apply to the scrollbars, however make it a named style with x:Key="..." element:
<Application.Resources>
    <Style x:Key="MyScrollBarStyle" TargetType="ScrollBar">
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="Width" Value="Auto"/>
                <Setter Property="Height" Value="50" />
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Width" Value="50"/>
                <Setter Property="Height" Value="Auto" />
            </Trigger>
        </Style.Triggers>                   
    </Style> 
</Application.Resources>

Now each time you want to draw a scrollbar with this style, simply add Style="{StaticResource MyScrollBarStyle}" to the scrollbar tag.

Mike
  • 1,225
  • 10
  • 21
  • Thanks, but I REALLY want to apply the style to ALL scrollbars. And, as I told, this does not change the style of scrollbars inside other controls. – Adam Calvet Bohl Jan 22 '20 at 11:25
  • I've found this thread https://social.msdn.microsoft.com/Forums/vstudio/en-US/ad8548f9-7ad2-4980-acb3-17c0088f4038/create-a-style-trigger-for-quotparent-of-a-given-type-existsquot?forum=wpf discussing something similar to what you need. Unfortunately, there aren't enough details given there so I can verify this solution on a short notice. – Mike Jan 22 '20 at 12:16
  • Damn, I've read your question again and it occurred to me that you want the opposite of what I was proposing. Nevertheless, I've checked and the App.xaml solution changes the size of ALL scrollbars, hence there must be something in your code that styles the scrollbars of panels separately. Search your code for PART_VerticalScrollBar and PART_HorizontalScrollBar and make sure those are not taking precedence over your code. I'm sorry for my previous answer, it was totally not applicable. – Mike Jan 23 '20 at 11:39