Change ScrollBar background color in ScrollViewer wpf

I know how to change the background color of the scroll bar:

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

here is a photo with my red background: enter image description here

How can I do the same with ScrollViewer? I have a grid inside my ScrollViewer, and if I change the properties of the ScrollViewer, it looks like it changes the properties of the content inside my grid.

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

which produces:

enter image description here

with the contents of my grid named "Parent" on the left. How can I put a red background on this ScrollViewer?

+6
source share
2 answers

Set the ScrollViewer style to the style that you create separately. Here are two links in which authors first create a style and then apply this style to 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

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

In the above code, the programmer can give any color value that he / she wants to set. For example, I set the background color of the scroll bar to white.

0
source

Source: https://habr.com/ru/post/891682/


All Articles