2009-09-01 69 views
4

我想改變一個滑塊的軌道。有沒有辦法做到這一點?如何更改滑塊的軌道模板?

<Track x:Name="PART_Track" Grid.Row="1"> 
    <Track.DecreaseRepeatButton> 
     <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" Command="{x:Static Slider.DecreaseLarge}"/> 
    </Track.DecreaseRepeatButton> 
    <Track.IncreaseRepeatButton> 
     <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" Command="{x:Static Slider.IncreaseLarge}"/> 
    </Track.IncreaseRepeatButton> 
    <Track.Thumb> 
     <Thumb x:Name="Thumb" Style="{StaticResource HorizontalSliderThumbStyle}"/> 
    </Track.Thumb> 

回答

4

的軌道剛剛處理拇指和重複按鈕link text的定位。軌道的實際外觀在滑塊的模板中。

要改變一下了 「跟蹤」 更改以下區域,PART_SelectionRange,在控制模板

<ControlTemplate TargetType="{x:Type Slider}"> 
<Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 
     <TickBar x:Name="TopTick" Height="4" Visibility="Collapsed" Grid.Row="0" Fill="{TemplateBinding Foreground}" Placement="Top"/> 
     <TickBar x:Name="BottomTick" Height="4" Visibility="Collapsed" Grid.Row="2" Fill="{TemplateBinding Foreground}" Placement="Bottom"/> 
     <Border Margin="5,0" VerticalAlignment="center" Height="20.0" Grid.Row="1" Background="{StaticResource HorizontalSliderTrackNormalBackground}" BorderBrush="{StaticResource HorizontalSliderTrackNormalBorder}" BorderThickness="1" CornerRadius="1"> 
      <Canvas Margin="-6,-1"> 
       <Rectangle x:Name="PART_SelectionRange" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Stroke="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" StrokeThickness="1.0" Height="4.0" Visibility="visible"/> 
      </Canvas> 
     </Border> 
     <Track x:Name="PART_Track" Grid.Row="1"> 
      <Track.DecreaseRepeatButton> 
       <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" Command="{x:Static Slider.DecreaseLarge}"/> 
      </Track.DecreaseRepeatButton> 
      <Track.IncreaseRepeatButton> 
       <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" Command="{x:Static Slider.IncreaseLarge}"/> 
      </Track.IncreaseRepeatButton> 
      <Track.Thumb> 
       <Thumb x:Name="Thumb" Style="{StaticResource HorizontalSliderThumbStyle}"/> 
      </Track.Thumb> 
     </Track> 
    </Grid> 
</Border>