IXRSolidColorBrush (Compact 2013)

3/28/2014

This class paints an area with a solid color; create instances of IXRSolidColorBrush by using IXRApplication::CreateObject().

Syntax

class IXRSolidColorBrush : public IXRBrush

Inheritance Hierarchy

IXRDependencyObject

    IXRBrush

        IXRSolidColorBrush

Methods

Method

Description

IXRSolidColorBrush::GetColor

Retrieves the color of this brush.

IXRSolidColorBrush::SetColor

Sets the color of this brush.

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

When you set a solid color to paint with, you can use the RGB macro or the RGBA macro to create a color value for this brush. If you use the RGB macro to create a color value, the color value will have an opacity of 0 (zero), which is transparent. Use the RGBA macro to create a color with a specified opacity.

You can animate an IXRSolidColorBrush by using either IXRColorAnimation or IXRColorAnimationUsingKeyFrames. Usually, you animate the brush by indirectly targeting a property of a target object, such as Fill or Color. To do this, set the attached property "Storyboard.TargetProperty" on an IXRColorAnimation object by using its inherited method IXRDependencyObject::SetAttachedProperty.

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

You can also define a solid-color brush as an attribute 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 brush in the source XAML for your application, see the SolidColorBrush Class on MSDN.

Example

The following code example creates a solid color brush, uses it to fill a rectangle object, and then creates an animation storyboard that will animate the color of the brush at run-time.

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 CreateBrushAnimation(IXRApplication* pApplication, IXRRectangle* pRect, IXRStoryboard* pStoryboard)
{
  // create a solid color brush
  IXRSolidColorBrushPtr pPaintBrush;
  COLORREF oldBrushColor = RGBA(0,0,255,255);

  pApplication->CreateObject(&pPaintBrush);
  pPaintBrush->SetColor(oldBrushColor);

  // paint an existing shape with that brush
  pRect->SetFill(pPaintBrush);
  pRect->SetName(L"PaintedRectangle");

  // now create an animation that will change it to a new color when 
  // triggered
  COLORREF newBrushColor = RGBA(0,0,128,255);
  XRTimeSpan ColoringTime = XRTimeSpan(50000);
  
  IXRColorAnimationPtr pColorAnimation;
  pApplication->CreateObject(&pColorAnimation);

  pColorAnimation->SetAttachedProperty(L"Storyboard.TargetName", NULL, L"PaintedRectangle");
  pColorAnimation->SetAttachedProperty(L"Storyboard.TargetProperty", NULL, L"Fill");
  pColorAnimation->SetTo(newBrushColor);
  pColorAnimation->SetBeginTime(&ColoringTime);

  // add it to a storyboard's collection of animations
  IXRTimelineCollectionPtr pChildren;
  int* index = 0;
  pStoryboard->GetChildren(&pChildren);
  pChildren->Add(pColorAnimation, index);
}

To run this code example, the visual tree must already be generated, the visual tree must contain shape and storyboard elements, and IXRShape and IXRStoryboard instances must already be created. Notice that the target name of the IXRRectangle object is set in C++ code by calling the inherited method IXRDependencyObject::SetName. This named object has the target property to animate.

.NET Framework Equivalent

System.Windows.Media.SolidColorBrush

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Visual Appearance