Partager via


IXRGradientStopCollection (Windows Embedded CE 6.0)

1/6/2010

This class represents a collection of IXRGradientStop objects that can be accessed individually by index.

Syntax

class IXRGradientStopCollection : public IXRCollection<IXRGradientStop*, IXRDependencyObject*>

Methods

IXRGradientStopCollection inherits the methods from the template class IXRCollection<In_T, Out_T>. It uses In_T parameters of type IXRGradientStop* and uses Out_T parameters of type IXRDependencyObject*.

Remarks

The IXRGradientStop information stored by IXRGradientBrush classes in the IXRGradientStopCollection describes the set of coordinates along an axis where the blend effect between two colors stops. This information determines the visual appearance of the blend effect achieved with a specific IXRGradientBrush.

You can obtain a pointer to this collection by calling IXRGradientBrush::GetGradientStops. Then, you can use the methods inherited from IXRCollection to add, remove, or retrieve items. You can also clear the complete collection by calling the inherited method IXRCollection<In_T, Out_T>::Clear.

To create a new collection, use the IXRApplication::CreateObject(IID,Object) method to create an empty IXRGradientStopCollection object. Then, you can use CreateObject to create multiple IXRGradientStop objects that each define the location and color of a transition point for a blend effect. Next, you can add each IXRGradientStop object to the IXRGradientStopCollection collection by calling the inherited method IXRCollection<In_T, Out_T>::Add. Finally, you can set the new collection for an IXRGradientBrush by calling IXRGradientBrush::SetGradientStops.

You can also define a gradient-stop collection 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 collection in the source XAML for your application, see this Microsoft Web site.

Example

The following code example shows how to create an IXRGradientStopCollection that defines a simple gradient from red to blue, set it as the value of an IXRLinearGradientBrush, and set it to the background of a canvas in the visual tree.

#include <windows.h>
#include <XamlRuntime.h>
#include <XRPtr.h>


void DefineGradientBrush(IXRApplication* pApplication, IXRFrameworkElement* pRootElement, IXRLinearGradientBrush* myBrush)
{
  // Create two gradient stops for red and blue color values
  IXRGradientStopPtr redGradientStop;
  IXRGradientStopPtr blueGradientStop;

  pApplication->CreateObject(IID_IXRGradientStop, &redGradientStop);
  pApplication->CreateObject(IID_IXRGradientStop, &blueGradientStop);

  COLORREF Red  = RGB(255,0,0);
  COLORREF Blue = RGB(0,0,255);

  float redOffset = 0;
  float blueOffset = 1;

  redGradientStop->SetColor(Red);
  redGradientStop->SetOffset(redOffset);

  blueGradientStop->SetColor(Blue);
  blueGradientStop->SetOffset(blueOffset);

  // Create a collection that stores both new gradient stops
  IXRGradientStopCollection* RBgradient;
  int indexRed;
  int indexBlue;
  pApplication->CreateObject(IID_IXRGradientStopCollection, &RBgradient);

  RBgradient->Add(redGradientStop, &indexRed);
  RBgradient->Add(blueGradientStop, &indexBlue);

  // Add the collection to the provided linear-gradient brush
  
  pApplication->CreateObject(IID_IXRLinearGradientBrush, &myBrush);

  myBrush->SetGradientStops(RBgradient);

  // Paint the background of a canvas in the visual tree with the new brush
  IXRCanvasPtr pCanvas;
  pRootElement->FindName(L"MyCanvas", &pCanvas);
  pCanvas->SetBackground(myBrush);
}

To run the previous code example, you must 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 example, see IXRApplication, IXRButton, IXRVisualHost, and IXRCanvas.

Inheritance Hierarchy

IXRDependencyObject

    IXRCollection<In_T, Out_T>

        IXRGradientStopCollection

.NET Framework Equivalent

System.Windows.Media.GradientStopCollection

Requirements

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

See Also

Reference

Classes for Collection Management