Compartilhar via


IXRPath (Compact 2013)

3/28/2014

This class draws a series of connected lines and curves. The line and curve dimensions are declared through the IXRPath::SetData method, and can be specified either with an IXRPath-specific mini-language, or with an object model.

Syntax

class IXRPath : public IXRShape

Inheritance Hierarchy

IXRDependencyObject

    IXRUIElement

        IXRFrameworkElement

            IXRShape

                IXRPath

Methods

Method

Description

IXRPath::GetData

Retrieves a geometry object that specifies the shape to be drawn with this path.

IXRPath::SetData

Sets a geometry object that specifies the shape to be drawn with this path.

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

Fundamentally, a path is a shape and it inherits from IXRShape. However, IXRPath can be used to create much more complex two-dimensional graphics than the other shapes can create. The IXRPath object can draw closed or open shapes, lines, and curves. For a description of the shapes that the IXRPath object supports, see the IXRPath::SetData method.

IXRPath supports two parallel techniques for declaring its contents: as an object model that uses discrete geometries declared in markup or code, or as mini-language declared in markup. The geometry object model can use the IXRGeometryGroup object as data in order to specify a composite of multiple geometries. The mini-language is comparable to a pathing-language output used in some graphics tools.

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

You can also define a path element in 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 Path Class on MSDN. For more information about how to use the mini-language definition format for a path element in XAML markup, see Path Markup Syntax on MSDN.

Note

For best performance avoid explicitly setting the Width and Height of an IXRPath. Calling the inherited methods IXRFrameworkElement::SetWidth or IXRFrameworkElement::SetHeight will result in additional stretching, which slows performance. Instead, you should rely on the explicitly set coordinates of the IXRPath object and its contained data to control its shape and position. In effect, the IXRPath object will have a natural height/width, although those values are not reported to the object model. For more information, see IXRShape::SetStretch.

Example

The following code example uses an IXRPath to create an ellipse object by using predefined Brush objects and ellipse geometry, and then adds it to an IXRCanvas that is currently in the visual tree. If the window is already displayed on-screen, the path will be drawn automatically when XAML for Windows Embedded detects the change and refreshes the visual-host window. 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 CreatePathOnCanvas(IXRApplication* pApplication, IXRCanvas* pCanvas, 
IXRSolidColorBrush* myGoldBrush, IXRSolidColorBrush* myBlackBrush)
{
   XRPoint myEllipsePoint; 
   myEllipsePoint.x = 50;
   myEllipsePoint.y = 50;
   float RadX = 50;
   float RadY = 50;
   float width = 1;

   //  Note: This code uses smart pointers to ensure that all interfaces are released
   IXREllipseGeometryPtr myEllipseGeometry; 
   IXRPathPtr circularPath; 
   IXRUIElementCollectionPtr pCanvasChildren; 

   //
   // Create an ellipse geometry for the path object.
   //

   //  Note: CreateObject is a Helper Template Overload Method 
   pApplication->CreateObject(&myEllipseGeometry);
   myEllipseGeometry->SetCenter(&myEllipsePoint);
   myEllipseGeometry->SetRadiusX(RadX);
   myEllipseGeometry->SetRadiusY(RadY); 

   //
   // Create a path object
   //

   pApplication->CreateObject(&circularPath);
   circularPath->SetFill(myGoldBrush);
   circularPath->SetStroke(myBlackBrush);
   circularPath->SetStrokeThickness(width);
   circularPath->SetData(myEllipseGeometry); 

   //
   // Add the path object to the collection of child elements for an
   // existing canvas object
   //

   int index; 
   pCanvas->GetChildren(&pCanvasChildren);
   pCanvasChildren->Add(circularPath, &index); 
}

The previous code example assumes that two IXRSolidColorBrush objects have already been created that each represents the colors gold and black, respectively. For more information on the objects used in this code example, see IXRApplication, IXRSolidColorBrush, IXRCanvas, XRPtr<Interface>, IXREllipseGeometry, and IXRApplication::CreateObject(IID,Object). The following illustration depicts the visual result of the previous code example:

Path with Ellipse Geometry

.NET Framework Equivalent

System.Windows.Shapes.Path

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for UI Element Management