2016-10-31 80 views
2

我正在嘗試改變水平放置的ScrollBar的縮略圖寬度。WPF - 水平滾動條縮略圖寬度

我有這個ControlTemplate

<ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}"> 
     <Grid > 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition MaxWidth="100"/> 
       <ColumnDefinition Width="0.00001*"/> 
       <ColumnDefinition MaxWidth="100"/> 
      </Grid.ColumnDefinitions> 
      <Border Grid.ColumnSpan="3" CornerRadius="2" Background="#F0F0F0" /> 
      <RepeatButton Grid.Column="0" Style="{StaticResource ScrollBarLineButton}" Width="100" Command="ScrollBar.LineLeftCommand" Content="M 16 0 L 16 32 L 0 16 Z" /> 
      <Track Name="PART_Track" Grid.Column="1" IsDirectionReversed="False"> 
       <Track.DecreaseRepeatButton> 
        <RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" Width="50"/> 
       </Track.DecreaseRepeatButton> 
       <Track.Thumb> 
        <Thumb Style="{StaticResource ScrollBarThumb}" Margin="0,1,0,1" Background="{StaticResource NormalBrush}" BorderBrush="{StaticResource NormalBorderBrush}" /> 
       </Track.Thumb> 
       <Track.IncreaseRepeatButton> 
        <RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageRightCommand" /> 
       </Track.IncreaseRepeatButton> 
      </Track> 
      <RepeatButton Grid.Column="3" Style="{StaticResource ScrollBarLineButton}" Width="100" Command="ScrollBar.LineRightCommand" Content="M 0 0 L 16 16 L 0 32 Z"/> 
     </Grid> 
    </ControlTemplate> 

而且ScrollBarThumb是:

<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}"> 
     <Setter Property="SnapsToDevicePixels" Value="True"/> 
     <Setter Property="OverridesDefaultStyle" Value="true"/> 
     <Setter Property="IsTabStop" Value="false"/> 
     <Setter Property="Focusable" Value="false"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type Thumb}">       
        <Border CornerRadius="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" /> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

拇指現在看起來是這樣的:

enter image description here

當我在設定,大拇指看起來像已經擴大,但似乎有什麼東西是隱藏它: enter image description here

謝謝。

+0

請給,充分xaml。我想在我的環境中運行它。我記得我曾經遇到過這個問題並修復過它。我的意思是所有樣式和畫筆都運行它,但沒有「資源缺失」異常。 –

+0

@ Mr.B,參見http://www.codeproject.com/Articles/37366/Styling-A-ScrollViewer-Scrollbar-In-WPF –

+0

我不能從這裏複製這段代碼:那裏有很多無效的字符編譯錯誤,如「代替」給我的代碼,我可以直接運行沒有解決方法 –

回答

0

感謝grek40,我找到了答案。

添加ViewportSize="NaN"

<Track Name="PART_Track" Grid.Column="1" IsDirectionReversed="False"> 

示出了整個拇指和然後設置其屬性Width有預期的效果。