因为ScrollViewer只支持一个子对象,所以我添加了一个网格来包装textbox。
在我的例子中,我应用了一个覆盖样式来使文本框变成蓝色。
如果从网格中删除整个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>