views:

343

answers:

1

Hello, and thank you for looking into my question. I would like to customize the ScrollBar in my ScrollViewer. No problem. But wait. When I do that, it also changes the ScrollBar of the inner controls. I don't want to impact those ScrollBars. How do I specify the correct scope?

Here's the XAML that almost works:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  <ScrollViewer>  
    <ScrollViewer.Resources>
      <Style TargetType="{x:Type ScrollBar}">
        <Setter Property="Background" Value="Red" />
      </Style>
    </ScrollViewer.Resources>
    <TextBox Height="200" Width="200" VerticalScrollBarVisibility="Visible" />
  </ScrollViewer>
</Page>
+1  A: 

Because ScrollViewer supports only one child object I added a Grid to wrap the textbox. In my case I applied an override style to make the text box blue. If you remove the entire setter from the Grid you get the default.

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; 
    <Grid>
        <ScrollViewer>
            <ScrollViewer.Resources>
                <Style TargetType="{x:Type ScrollBar}">
                    <Setter Property="Background" Value="Red" />
                </Style>
            </ScrollViewer.Resources>
            <Grid>
                <Grid.Resources>
                    <Style TargetType="{x:Type ScrollBar}">
                        <!-- remove setter to get default -->
                        <Setter Property="Background" Value="Blue" />
                    </Style>
                </Grid.Resources>
                <TextBox Height="200" Width="200" VerticalScrollBarVisibility="Visible" />
            </Grid>    
        </ScrollViewer>
    </Grid>
</Page> 
Zamboni