Export (0) Print
Expand All

Track Class

Represents a control primitive that handles the positioning and sizing of a Thumb control and two RepeatButton controls that are used to set a Value.

Namespace:  System.Windows.Controls.Primitives
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
public class Track : FrameworkElement

The Track control does not have a default ControlTemplate. Its ControlTemplate is implemented as part of the ControlTemplate of the ScrollBar and Slider controls. The Track has a Thumb control and two RepeatButton controls that are used to change the Value property of the Track control.

The following illustration shows a Track on a slider.

A Track on a Slider

RepeatButton, Thumb

The following table shows the Track properties and the corresponding RangeBase properties that they automatically bind to. When either property changes, the bound property also changes.

The following table shows the Track properties and the corresponding ScrollBar properties to which they bind when a Track is part of a ScrollBar control and the Track properties are not explicitly set.

The following table shows the Track properties and the corresponding Slider properties to which they bind when a Track is part of a Slider control and the Track properties are not explicitly set.

Additionally, the Delay properties for the RepeatButton controls for a Slider control bind with the Delay properties for the RepeatButton controls of the Track control.

When a Track is used to scroll content, the size of the Thumb control is proportional to the percentage of the content that appears in the viewable area or viewport. The following illustration shows an example of a ScrollViewer control that implements a Track control.

A ScrollBar that has a Track control

ScrollBar illlustration

The following calculation is used to compute the size of the Thumb.

thumbSize = (viewportSize/(maximumminimum+viewportSize))×trackLength

The viewportSize parameter is the value of the ViewportSize property. The maximum and minimum parameters correspond to the Maximum and Minimum property values. The value of the expression maximumminimum+viewportSize is the size of the scrollable content. Note that the value of the Maximum property represents the Value of the Track when the content is scrolled to the bottom. This Maximum value is not the same as the length or extent of the content. For a more detailed explanation, see Track.Maximum.

The Value of a Track in a ScrollBar increases from top to bottom or from left to right depending on the orientation of the ScrollBar. Similarly, the Value of a Track in a Slider increases from bottom to top or from left to right depending on the orientation of the Slider. To change the direction of increasing value, set the IsDirectionReversed property of the Track to true.

The following example shows how to define a Track control in a ScrollBar ControlTemplate.

<ControlTemplate TargetType="{x:Type ScrollBar}">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="12"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="12" />
      <RowDefinition Height="*"/>
      <RowDefinition Height="12" />
    </Grid.RowDefinitions>
    <Border Grid.Row="1" BorderThickness="0" 
            Background="Transparent" CornerRadius="4"/>
    <RepeatButton Grid.Row="0" 
                  Style="{DynamicResource Scrollbar_LineButton}" 
                  Command="ScrollBar.LineUpCommand" Content=" ^" />

    <!--IsDirectionReversed set to true draws a ScrollBar with a 
        Track whose lowest value is at the bottom.
        The default orientation of a ScrollBar is for the Track
        values to decrease from top to bottom.-->
    <Track Grid.Row="1" Name="PART_Track"
           IsDirectionReversed="true">
      <Track.DecreaseRepeatButton>
        <RepeatButton Style="{DynamicResource ScrollBar_UpTrack}"/>
      </Track.DecreaseRepeatButton>
      <Track.Thumb>
        <Thumb Style="{DynamicResource ScrollBar_HorizontalThumb}"/>
      </Track.Thumb>
      <Track.IncreaseRepeatButton>
        <RepeatButton Style="{DynamicResource ScrollBar_DownTrack}"/>
      </Track.IncreaseRepeatButton>
    </Track>
    <RepeatButton Grid.Row="2" 
                  Style="{DynamicResource Scrollbar_LineButton}" 
                  Command="ScrollBar.LineDownCommand" Content=" v" />
  </Grid>
</ControlTemplate>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft