This documentation is archived and is not being maintained.

ScrollBar.ViewportSize Property

Updated: February 2009

Gets or sets the amount of the scrollable content that is currently visible. This is a dependency property.

Namespace:  System.Windows.Controls.Primitives
Assembly:  PresentationFramework (in PresentationFramework.dll)

public double ViewportSize { get; set; }
<object ViewportSize="double" .../>

Property Value

Type: System.Double
The amount of the scrollable content that is currently visible. The default is 0.

Identifier field


Metadata properties set to true


The value of the ViewportSize property is used to calculate the size of the Thumb control in the ScrollBar control. You typically set the ViewportSize property when the ScrollBar is part of a ControlTemplate by using template binding. For example, when the ScrollBar is in a ControlTemplate of a ScrollViewer control, you can template bind ViewportSize to ScrollViewer.ViewportHeight. The Thumb control's size represents the amount of a ScrollViewer control's content that is visible. If 25 percent of a ScrollViewer control's content is visible, the Thumb occupies 25 percent of the track in the ScrollBar.

You can decide which units ViewportSize uses. When you set this property, make sure that the ViewportSize, Minimum, Maximum, and Value properties use the same units.

The following illustration shows how the Thumb size reflects the amount of content that is visible.

The track length and thumbsize of a ScrollBar

The following example puts two ScrollBar controls in the ControlTemplate of a ScrollViewer. The ViewportSize property is template bound to the ScrollViewer.ViewportHeight property of the vertical ScrollBar. The ViewportSize property is template bound to the ScrollViewer.ViewportWidth property of the horizontal ScrollBar.

<Style x:Key="LeftScrollViewer" TargetType="{x:Type ScrollViewer}">
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
      <ControlTemplate TargetType="{x:Type ScrollViewer}">
            <ColumnDefinition Width="Auto"/>
            <RowDefinition Height="Auto"/>

          <ScrollContentPresenter Grid.Column="1"/>

          <ScrollBar Name="PART_VerticalScrollBar"
            Value="{TemplateBinding VerticalOffset}"
            Maximum="{TemplateBinding ScrollableHeight}"
            ViewportSize="{TemplateBinding ViewportHeight}"
            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
          <ScrollBar Name="PART_HorizontalScrollBar"
            Value="{TemplateBinding HorizontalOffset}"
            Maximum="{TemplateBinding ScrollableWidth}"
            ViewportSize="{TemplateBinding ViewportWidth}"
            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>


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




February 2009

Clarified remarks about how to use ViewportSize. Also provided a new example.

Customer feedback.