Partager via


IXRScrollViewer (Windows Embedded CE 6.0)

1/6/2010

This class represents a scrollable region that can contain other UI elements.

Syntax

class IXRScrollViewer : public IXRContentControl

Methods

Method Description

IXRScrollViewer::AddScrollChangedEventHandler

Attaches a delegate to the ScrollChanged event for this scroll viewer. When the scroll viewer raises the ScrollChanged event, this delegate will be invoked.

IXRScrollViewer::GetComputedHorizontalScrollBarVisibility

Retrieves a value that indicates whether the horizontal scrollbar is visible inside this scroll viewer at run time.

IXRScrollViewer::GetComputedVerticalScrollBarVisibility

Retrieves a value that indicates whether the vertical scrollbar is visible inside this scroll viewer at run time.

IXRScrollViewer::GetExtentHeight

Retrieves the vertical size of all the content to display in this scroll viewer.

IXRScrollViewer::GetExtentWidth

Retrieves the horizontal size of all the content to display in this scroll viewer.

IXRScrollViewer::GetHorizontalOffset

Retrieves a value that contains the horizontal offset of the scrolled content in this scroll viewer.

IXRScrollViewer::GetHorizontalScrollBarVisibility

Retrieves a value that indicates whether a horizontal scrollbar should be displayed inside this scroll viewer.

IXRScrollViewer::GetScrollableHeight

Retrieves a value that represents the vertical size of the remaining area that can be scrolled, which is the difference between the height of the extent and the height of the viewport.

IXRScrollViewer::GetScrollableWidth

Retrieves a value that represents the horizontal size of the remaining area that can be scrolled, which is the difference between the width of the extent and the width of the viewport.

IXRScrollViewer::GetVerticalOffset

Retrieves a value that contains the vertical offset of the scrolled content in this scroll viewer.

IXRScrollViewer::GetVerticalScrollBarVisibility

Retrieves a value that indicates whether a vertical scrollbar should be displayed in this scroll viewer.

IXRScrollViewer::GetViewportHeight

Retrieves a value that contains the vertical size of the viewable content in this scroll viewer.

IXRScrollViewer::GetViewportWidth

Retrieves a value that contains the horizontal size of the viewable content in this scroll viewer.

IXRScrollViewer::RemoveScrollChangedEventHandler

Removes a delegate from the ScrollChanged event for this scroll viewer.

IXRScrollViewer::ScrollToHorizontalOffset

Scrolls the content that is within the scroll viewer to the specified horizontal offset position.

IXRScrollViewer::ScrollToVerticalOffset

Scrolls the content that is within the scroll viewer to the specified vertical offset position.

IXRScrollViewer::SetHorizontalScrollBarVisibility

Sets a value that indicates whether a horizontal scrollbar should be displayed inside this scroll viewer.

IXRScrollViewer::SetVerticalScrollBarVisibility

Sets a value that indicates whether a vertical scrollbar should be displayed in this scroll viewer.

Remarks

The IXRScrollViewer object contains a content element and up to two IXRScrollBar controls. The content for the scrolling region, such as an IXRTextBlock object, can be supplied by calling the inherited method IXRContentControl::SetContent. The extent includes all the content of the scroll viewer. The visible area of the content is the viewport.

You can control the conditions under which the vertical and horizontal IXRScrollBar controls appear by calling IXRScrollViewer::SetHorizontalScrollBarVisibility and IXRScrollViewer::SetVerticalScrollBarVisibility. If they are set to XRScrollBarVisibility_Hidden, you can use IXRScrollViewer::GetComputedHorizontalScrollBarVisibility and IXRScrollViewer::GetComputedVerticalScrollBarVisibility in code to see what their actual state is at run time.

You can also define a scroll viewer in Microsoft Silverlight 2 XAML. For information about the differences between XAML in Silverlight for Windows Embedded and Silverlight 2, see Differences Between Silverlight for the Web and Silverlight for Windows Embedded. For more information about how to define this element in the source XAML for your application, see this Microsoft Web site.

To make the entire window scrollable, you can add an IXRScrollViewer as the child element of the IXRPanel-derived object for the application, and then add another IXRPanel-derived object that contains the child UI elements as the content of IXRScrollViewer by using IXRContentControl::SetContent.

Example

The following example code creates an IXRScrollViewer object that is the root element of a window. Its content is an IXRCanvas object that contains an IXRButton object. The scroll viewer in this example provides scrolling for the entire application window.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

#include "XamlRuntime.h"
#include "XRDelegate.h"

void CreateScrollableCanvas(IXRApplication* pApplication, IXRFrameworkElement* pVisualRoot, 
CustomEventHandler* HandlerObject)
{
     // Initialize variables and create new objects 
     IXRScrollViewer* pScrollableRegion;
     IXRCanvas* pCanvas;
     IXRButton* pButton;
     IXRTextBlock* pText;
     
     pApplication->CreateObject(IID_IXRScrollViewer, &pScrollableRegion);
     pApplication->CreateObject(IID_IXRCanvas, &pCanvas);
     pApplication->CreateObject(IID_IXRButton, &pButton);
     pApplication->CreateObject(IID_IXRTextBlock, &pText);

     // Set values for the scroll viewer
     pScrollableRegion->SetHorizontalScrollBarVisibility(XRScrollBarVisibility_Visible);
     pScrollableRegion->SetVerticalScrollBarVisibility(XRScrollBarVisibility_Visible);
     pScrollableRegion->AddScrollChangedEventHandler(CreateDelegate(&HandlerObject, &CustomEventHandler::OnScrollChanged));
     
     // Set values for the text block
     pText->SetText(L"OK");

     // Define a Margin for positioning the button
     XRThickness btnMargin;
     btnMargin.Left = 2;
     btnMargin.Top = 3;
     btnMargin.Right = 12;
     btnMargin.Bottom = 42;

     // Set values for the button
     pButton->SetTabIndex(0);
     pButton->AddClickEventHandler(CreateDelegate(&HandlerObject, &CustomEventHandler::OnClick));
     pButton->SetMargin(&btnMargin);
     pButton->SetContent(&pText);

     // Add the button to the new canvas
     IXRUIElementCollection* pChildElements;
     pCanvas->GetChildren(&pChildElements);
     pChildElements->Add(&pButton, NULL);

     // Add the new canvas as the content of the scroll viewer
     pScrollableRegion->SetContent(&pCanvas);

     // Add the scroll viewer to the visual root
     IXRUIElementCollection* pRootElements;
     pVisualRoot->GetChildren(&RootElements);
     pRootElements->Add(&pScrollableRegion, NULL);

}

To run this code sample you must have created an IXRApplication instance, created an IXRVisualHost object and loaded the source XAML into a visual tree, and implemented custom event-handler methods in an object called CustomEventHandler.

Inheritance Hierarchy

IXRDependencyObject

    IXRUIElement

        IXRFrameworkElement

            IXRControl

                IXRContentControl

                    IXRScrollViewer

.NET Framework Equivalent

System.Windows.Controls.ScrollViewer

Requirements

Header XamlRuntime.h
sysgen SYSGEN_XAML_RUNTIME
Windows Embedded CE Windows Embedded CE 6.0 R3

See Also

Reference

Classes for UI Element Management

Other Resources