IXRScrollViewer (Compact 2013)

3/28/2014

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

Syntax

class IXRScrollViewer : public IXRContentControl

Inheritance Hierarchy

IXRContentControl

     IXRScrollViewer

Methods

Method

Description

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 to display a vertical scrollbar 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::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 to display a horizontal scrollbar inside this scroll viewer.

IXRScrollViewer::SetVerticalScrollBarVisibility

Sets a value that indicates whether to display a vertical scrollbar in this scroll viewer.

Thread Safety

Members of this class are thread-safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

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.

When you create a class instance, use an IXRScrollViewerPtr smart pointer instead of a raw interface pointer. For more information, see XRPtr<Interface>.

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

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"
#include "XRPtr.h"

class CustomObject
{
public:

    IXRVisualHostPtr g_pHost;

    HRESULT  SetHost(IXRVisualHost* pHost)
       {
            HRESULT hr;
            ASSERT(! g_pHost);
            if(NULL == pHost)
            {
                 hr = S_FALSE;
                 return hr;
            
            }
            
            g_pHost = pHost;
            
           hr = S_OK;
            return hr;
       }

          HRESULT OnClick(IXRDependencyObject* pSender, XRMouseButtonEventArgs* pArgs)
     {
        if((NULL == pSender) || (NULL == pArgs))
          {
               return E_INVALIDARG;
          }
          // Get a brush from the visual tree
          IXRFrameworkElementPtr pRoot;
          IXRSolidColorBrushPtr pBrush;

          g_pHost->GetRootElement(&pRoot);
          pRoot->FindName(L"SelectedObjectColor", &pBrush);
          
          // Set the brush's color
          COLORREF BorderColor = RGB(0,0,128);
          pBrush->SetColor(BorderColor);
        
          // Change the object sender's border color in response to the click event
          IXRButtonPtr pButton;
        pSender->QueryInterface(IID_IXRButton, (void**)&pButton);
          pButton->SetBorderBrush((IXRBrush*)&pBrush);
     }
};

void CreateScrollableCanvas(IXRApplication* pApplication, IXRFrameworkElement* pVisualRoot, 
CustomObject* pObject)
{
     // Initialize variables and create new objects 
     IXRScrollViewerPtr pScrollableRegion;
     IXRCanvasPtr pCanvas;
     IXRButtonPtr pButton;
     IXRTextBlockPtr pText;
     
     pApplication->CreateObject(&pScrollableRegion);
     pApplication->CreateObject(&pCanvas);
     pApplication->CreateObject(&pButton);
     pApplication->CreateObject(&pText);

     // Set values for the scroll viewer
     pScrollableRegion->SetHorizontalScrollBarVisibility(XRScrollBarVisibility_Visible);
     pScrollableRegion->SetVerticalScrollBarVisibility(XRScrollBarVisibility_Visible);
     
     
     // 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(pObject, &CustomObject::OnClick));
     pButton->SetMargin(&btnMargin);
     pButton->SetContent(&pText);

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

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

     // Add the scroll viewer to the parent canvas for the window
     IXRUIElementCollectionPtr pChildren;     
          
      IXRCanvasPtr pParentCanvas;
     pVisualRoot->FindName(L"ParentCanvas", &pParentCanvas);
      pParentCanvas->GetChildren(&pChildren);
      pChildren->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.

.NET Framework Equivalent

System.Windows.Controls.ScrollViewer

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for UI Element Management