Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
ScrollViewer Class
 CanContentScroll Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ScrollViewer..::.CanContentScroll Property

Updated: July 2009

Gets or sets a value that indicates whether elements that support the IScrollInfo interface are allowed to scroll. This is a dependency property.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic (Declaration)
Public Property CanContentScroll As Boolean
Visual Basic (Usage)
Dim instance As ScrollViewer
Dim value As Boolean

value = instance.CanContentScroll

instance.CanContentScroll = value
C#
public bool CanContentScroll { get; set; }
Visual C++
public:
property bool CanContentScroll {
    bool get ();
    void set (bool value);
}
JScript
public function get CanContentScroll () : boolean
public function set CanContentScroll (value : boolean)
XAML Attribute Usage
<object CanContentScroll="bool" .../>

Property Value

Type: System..::.Boolean
true if content can scroll; otherwise, false. The default is false.

Identifier field

CanContentScrollProperty

Metadata properties set to true

None

Content in a ScrollViewer can be scrolled in terms of physical units or logical units. Physical units are device independent pixels. Logical units are used for scrolling items within an ItemsControl. The default behavior of the ScrollViewer is to use physical units to scroll its content. However in cases where the CanContentScroll is set to true, the content could use logical units to scroll. This is how item scrolling is achieved in ListBox, ListView and other controls that inherit from ItemsControl. If CanContentScroll is true, the values of the ExtentHeight, ScrollableHeight, ViewportHeight, and VerticalOffset properties are number of items, instead of a physical unit.

If you require physical scrolling instead of logical scrolling, wrap the host Panel element in a ScrollViewer and set its CanContentScroll property to false. Physical scrolling is the default scroll behavior for most Panel elements.

The following example demonstrates how to set the CanContentScroll property by using code. For the complete sample, see ScrollChanged Event Sample.

Visual Basic
Private Sub scrollTrue(ByVal sender As Object, ByVal args As RoutedEventArgs)
    sv1.CanContentScroll = True
    sv1.Height = 600
    myStackPanel.Visibility = Visibility.Visible
    btn1.Visibility = Visibility.Collapsed
End Sub
C#
private void scrollTrue(object sender, RoutedEventArgs e)
{
    sv1.CanContentScroll = true;
    sv1.Height = 600;
    myStackPanel.Visibility = Visibility.Visible;
    btn1.Visibility = Visibility.Collapsed;
}

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

Date

History

Reason

July 2009

Clarified remarks.

Content bug fix.

February 2009

Corrected default value.

Content bug fix.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker