Partager via


IXRRectangle (Compact 2013)

3/28/2014

This class represents a rectangle shape, which is outlined with a stroke and uses a brush to fill its rectangular region.

Syntax

class IXRRectangle : public IXRShape

Inheritance Hierarchy

IXRDependencyObject

    IXRUIElement

        IXRFrameworkElement

            IXRShape

**                IXRRectangle**

Methods

Method

Description

IXRRectangle::GetRadiusX

Retrieves the x-axis radius of the ellipse that is used to round the corners of this rectangle object.

IXRRectangle::GetRadiusY

Retrieves the y-axis radius of the ellipse that is used to round the corners of this rectangle object.

IXRRectangle::SetRadiusX

Sets the new x-axis radius of the ellipse that is used to round the corners of this rectangle object.

IXRRectangle::SetRadiusY

Sets the new y-axis radius of the ellipse that is used to round the corners of this rectangle object.

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

An IXRRectangle cannot support child objects. If you want to create a rectangular region that contains other objects, instead use IXRCanvas. You can also use a composite geometry as data to define a rectangular region, but in this case, you should use IXRRectangleGeometry instead of IXRRectangle.

The fill for a rectangle shape, or for any other shape that has a fill area, does not have to be a solid color. It can be any brush, including an image brush or a video brush. For more information, see IXRBrush.

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

You can also define a rectangle shape in Microsoft Silverlight 3 XAML. For information about the differences between XAML in XAML for Windows Embedded 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 Rectangle Class on MSDN.

Example

The following code example shows how to create a rectangle object, set properties on it, and add it to the content of an item in the element tree. It uses smart pointers and method overloads that help ensure type-safety.

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

void AddRectangleToExistingElementTree(IXRApplication* pApplication, IXRVisualHost * pVisualHost, IXRSolidColorBrush * pMyBlueBrush) 
{
    //  Note: This code uses smart pointers to ensure that 
    // all interfaces are released
    IXRRectanglePtr pRectangle;
    IXRFrameworkElementPtr pRootElement;
    IXRStackPanelPtr pStackPanel;
    IXRUIElementCollectionPtr pChildrenCollection;

    // Create a new rectangle from the IXRApplication object
    //
    //  Note: CreateObject is a Helper Template Overload Method 
    pApplication->CreateObject(IID_IXRRectangle, &pRectangle);  

    // Here's where you would set the properties you want on the rectangle
    // (for example, width, height, fill, border, etc.)
    // 
    pRectangle->SetWidth(10);
    pRectangle->SetFill(pMyBlueBrush);

    // Now get the root element (as stack panel) from your visual host 
    //and add the rectangle as a 
    // child in the panel's collection
    //

    // First find the stack panel named "MyStackPanel"
    //
    pVisualHost->GetRootElement(&pRootElement); 
    pRootElement->FindName(TEXT("MyStackPanel"), &pStackPanel);

    // Now get the children collection and add our new rectangle
    //
    pStackPanel->GetChildren(&pChildrenCollection);
    pChildrenCollection->Add(pRectangle, NULL);
}

The previous code example assumes that you have already created an application instance, parsed the XAML markup into an element tree, and obtained a pointer (pVisualHost) to the visual host. For more information on the programming elements used in this code example, see IXRApplication, IXRVisualHost, IXRStackPanel, XRPtr<Interface>, IXRApplication::CreateObject(IID,Object), and IXRUIElementCollection.

.NET Framework Equivalent

System.Windows.Shapes.Rectangle

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for UI Element Management