CompositionColorBrush CompositionColorBrush CompositionColorBrush CompositionColorBrush Class

Definition

Paints a SpriteVisual with a solid color.

public : sealed class CompositionColorBrush : CompositionBrush
struct winrt::Windows::UI::Composition::CompositionColorBrush : CompositionBrush
public sealed class CompositionColorBrush : CompositionBrush
Public NotInheritable Class CompositionColorBrush Inherits CompositionBrush
Inheritance
CompositionColorBrushCompositionColorBrushCompositionColorBrushCompositionColorBrush
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

Examples


SpriteVisual visual= compositor.CreateSpriteVisual();
visual.Brush = compositor.CreateColorBrush  (Colors.White);
          

using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
using System.Numerics;
 
…
public sealed partial class MainPage : Page
    {
        Compositor _compositor;
        ContainerVisual _root;
        SpriteVisual _visual;
 
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }
 
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Get compositor and create a solid color visual
            _root = ElementCompositionPreview.GetContainerVisual(MainGrid) as ContainerVisual;
            _compositor = _root.Compositor;
 
            // Create a solid color visual
            _visual = _compositor.CreateSpriteVisual();
            _visual.Brush = _compositor.CreateColorBrush( Windows.UI.Colors.Blue );
            _visual.Size = new Vector2(250, 250);
 
            // Set hard border mode to disable anti-aliasing
            _visual.BorderMode = CompositionBorderMode.Hard;
 
            // Set backface-visibility to hidden in event of 3D rotation
            _visual.BackfaceVisibility = CompositionBackfaceVisibility.Hidden;
 
            // Set composite mode to DestinationInvert to do color subtraction blending
            _visual.CompositeMode = CompositionCompositeMode.DestinationInvert;
 
            _root.Children.InsertAtTop(_visual);
 
	     // Create a child visual of the solid color visual
            SpriteVisual childVisual = _compositor.CreateSpriteVisual();
            childvisual.Brush = _compositor.CreateColorBrush( Windows.UI.Colors.Orange );
            childVisual.Size = new Vector2(250, 20);
            _visual.Children.InsertAtTop(childVisual);
 
        }
	 
	 private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Show or hide visual and subtree
            if (_visual.IsVisible)
            {
                _visual.IsVisible = false;
            }
            else
            {
                _visual.IsVisible = true;
            }
        }
 
    }
          
          

Animating the Color property using a key frame animation.


void ColorAnimation(SpriteVisual targetVisual)
{
  //
  // Create a key frame animation for the targetBrush.Color property
  //
  var animation = _compositor.CreateColorKeyFrameAnimation(); 
  animation.InsertKeyFrame(0.0f, Color.FromArgb(255, 0, 255, 0));
  animation.InsertKeyFrame(1.0f, Colors.Purple);
  targetVisual.Brush.StartAnimation("Color", animation);
}
          
          

Animating the Color property using an ExpressionAnimation.


void ColorExpression(SpriteVisual targetVisual, float screenWidth )
{
  var expression = _compositor.CreateExpressionAnimation("ColorLerp(ColorFrom, ColorTo, target.Offset.X / Width");
  expression.SetReferenceParameter("target", targetVisual);
  expression.SetColorParameter("ColorFrom", Colors.Green);
  expression.SetColorParameter("ColorTo", Colors.Purple);
  expression.SetFloatParameter("Width", screenWidth);
  targetVisual.Brush.StartAnimation("Color", expression);
}
          
          

Properties

Color Color Color Color

The color used to fill a SpriteVisual. Animatable.

Comment Comment Comment Comment

A string to associate with the CompositionObject.

(Inherited from CompositionObject)
Compositor Compositor Compositor Compositor

The Compositor used to create this CompositionObject.

(Inherited from CompositionObject)
Dispatcher Dispatcher Dispatcher Dispatcher

The dispatcher for the CompositionObject.

(Inherited from CompositionObject)
DispatcherQueue DispatcherQueue DispatcherQueue DispatcherQueue

Gets the DispatcherQueue for the CompostionObject.

(Inherited from CompositionObject)
ImplicitAnimations ImplicitAnimations ImplicitAnimations ImplicitAnimations

The collection of implicit animations attached to this object.

(Inherited from CompositionObject)
Properties Properties Properties Properties

The collection of properties associated with the CompositionObject.

(Inherited from CompositionObject)

Methods

Close Close Close Close

Closes the CompositionObject and releases system resources.

(Inherited from CompositionObject)
PopulatePropertyInfo(String,AnimationPropertyInfo) PopulatePropertyInfo(String,AnimationPropertyInfo) PopulatePropertyInfo(String,AnimationPropertyInfo) PopulatePropertyInfo(String,AnimationPropertyInfo)

Defines a property that can be animated.

(Inherited from CompositionObject)
StartAnimation(String,CompositionAnimation) StartAnimation(String,CompositionAnimation) StartAnimation(String,CompositionAnimation) StartAnimation(String,CompositionAnimation)

Connects an animation with the specified property of the object and starts the animation.

(Inherited from CompositionObject)
StartAnimationGroup(ICompositionAnimationBase) StartAnimationGroup(ICompositionAnimationBase) StartAnimationGroup(ICompositionAnimationBase) StartAnimationGroup(ICompositionAnimationBase)

Starts an animation group.

The StartAnimationGroup method on CompositionObject lets you start CompositionAnimationGroup. All the animations in the group will be started at the same time on the object.

(Inherited from CompositionObject)
StartAnimationGroupWithIAnimationObject(IAnimationObject,ICompositionAnimationBase) StartAnimationGroupWithIAnimationObject(IAnimationObject,ICompositionAnimationBase) StartAnimationGroupWithIAnimationObject(IAnimationObject,ICompositionAnimationBase) StartAnimationGroupWithIAnimationObject(IAnimationObject,ICompositionAnimationBase)

Starts an animation group on the specified target.

(Inherited from CompositionObject)
StartAnimationWithIAnimationObject(IAnimationObject,String,CompositionAnimation) StartAnimationWithIAnimationObject(IAnimationObject,String,CompositionAnimation) StartAnimationWithIAnimationObject(IAnimationObject,String,CompositionAnimation) StartAnimationWithIAnimationObject(IAnimationObject,String,CompositionAnimation)

Connects an animation with the specified property of the target object and starts the animation.

(Inherited from CompositionObject)
StopAnimation(String) StopAnimation(String) StopAnimation(String) StopAnimation(String)

Disconnects an animation from the specified property and stops the animation.

(Inherited from CompositionObject)
StopAnimationGroup(ICompositionAnimationBase) StopAnimationGroup(ICompositionAnimationBase) StopAnimationGroup(ICompositionAnimationBase) StopAnimationGroup(ICompositionAnimationBase)

Stops an animation group.

(Inherited from CompositionObject)
TryGetAnimationController(String) TryGetAnimationController(String) TryGetAnimationController(String) TryGetAnimationController(String)

Returns an AnimationController for the animation running on the specified property.

(Inherited from CompositionObject)

See also