2010-08-10 36 views
2

並感謝您查看我的問題。我想在ScrollViewer中自定義ScrollBar。沒問題。可是等等。當我這樣做時,它也會更改內部控件的ScrollBar。我不想影響那些ScrollBars。我如何指定正確的範圍?WPF/XAML自定義ScrollBar滾動條不帶內部控件中的自定義滾動條(如TextBox)

這裏的,幾乎與工作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> 

回答

2

因爲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>