Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of ScrollBar in ScrollViewer wpf

I know how to change the background color of a scrollbar:

<ScrollBar Height="27" Margin="36,96,12,0" Name="scrollBar1" Background="Red"></ScrollBar>

here is the picture with my red background: enter image description here

How could I do the same thing with ScrollViewer? I have a grid inside my ScrollViewer and if I change the properties of ScrollViewer it seem to change the properties of the content inside my grid.

<ScrollViewer>


    <Grid Name="Parent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
             ....
             ....
             ... etc

that produces:

enter image description here

with the content of my grid named Parent on the left. How could I place a red background on this ScrollViewer?

like image 394
Tono Nam Avatar asked Jun 29 '11 21:06

Tono Nam


2 Answers

<Window.Resources>
    <Style TargetType="ScrollBar">
        <Setter Property="Background" Value="White"/>
    </Style>
</Window.Resources>

In the above code, the programmer can give any color value he/she wants to set. For Eg, I have set the background color of my scrollbar to White.

like image 195
Girish Reddyvari Avatar answered Oct 06 '22 02:10

Girish Reddyvari


Set the ScrollViewer style equal to a style that you build separately. Here are two links where the authors create a style first, and then apply said style to a wpf control after that:

http://www.codeproject.com/Articles/37366/Styling-A-ScrollViewer-Scrollbar-In-WPF.aspx

http://www.eggheadcafe.com/tutorials/aspnet/f51ddf8c-5227-4f1b-a5df-ec3d1b3439ca/styling-the-wpf-scrollviewer.aspx

like image 26
MachinusX Avatar answered Oct 06 '22 03:10

MachinusX