WPF/XAML自定义ScrollViewer滚动条,内部控件中没有自定义滚动条(如TextBox)

WPF/XAML自定义ScrollViewer滚动条,内部控件中没有自定义滚动条(如TextBox),wpf,scrollbar,styles,scrollviewer,Wpf,Scrollbar,Styles,Scrollviewer,谢谢你调查我的问题。我想在ScrollViewer中自定义滚动条。没问题。但是等等。当我这样做时,它也会更改内部控件的滚动条。我不想影响那些滚动条。如何指定正确的范围 以下是几乎可以工作的XAML: <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Scroll

谢谢你调查我的问题。我想在ScrollViewer中自定义滚动条。没问题。但是等等。当我这样做时,它也会更改内部控件的滚动条。我不想影响那些滚动条。如何指定正确的范围

以下是几乎可以工作的XAML:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <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>

因为ScrollViewer只支持一个子对象,所以我添加了一个网格来包装文本框。 在我的例子中,我应用了一种覆盖样式,使文本框变成蓝色。 如果从网格中删除整个setter,则会得到默认设置

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <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>