LayerVisual.Effect Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the effect to be applied to the flattened representation of the children of a LayerVisual.
public:
property CompositionEffectBrush ^ Effect { CompositionEffectBrush ^ get(); void set(CompositionEffectBrush ^ value); };
CompositionEffectBrush Effect();
void Effect(CompositionEffectBrush value);
public CompositionEffectBrush Effect { get; set; }
var compositionEffectBrush = layerVisual.effect;
layerVisual.effect = compositionEffectBrush;
Public Property Effect As CompositionEffectBrush
Property Value
The effect to be applied to the flattened representation of the children of a LayerVisual.
Examples
This example shows how to apply a GaussianBlurEffect to a LayerVisual.
private async void InitComposition()
{
Compositor compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;
//Create LayerVisual
LayerVisual layerVisual = compositor.CreateLayerVisual();
layerVisual.Size = new Vector2(900,900);
//Create SpriteVisuals to use as LayerVisual child
SpriteVisual sv1 = compositor.CreateSpriteVisual();
sv1.Brush = compositor.CreateColorBrush(Windows.UI.Colors.Blue);
sv1.Size = new Vector2(300, 300);
sv1.Offset = new Vector3(200, 200, 0);
SpriteVisual sv2 = compositor.CreateSpriteVisual();
sv2.Brush = compositor.CreateColorBrush(Colors.Red);
sv2.Size = new Vector2(300, 300);
sv2.Offset = new Vector3(400, 400, 0);
//Add children to the LayerVisual
layerVisual.Children.InsertAtTop(sv1);
layerVisual.Children.InsertAtTop(sv2);
//Create Effect
var graphicsEffect = new GaussianBlurEffect
{
Name = "Blur",
Source = new CompositionEffectSourceParameter("Backdrop"),
BlurAmount = 10.0f,
BorderMode = EffectBorderMode.Hard,
Optimization = EffectOptimization.Balanced
};
var blurEffectFactory = compositor.CreateEffectFactory(graphicsEffect,
new[] { "Blur.BlurAmount" });
var blurBrush = blurEffectFactory.CreateBrush();
//Apply Effect
layerVisual.Effect = blurBrush;
ElementCompositionPreview.SetElementChildVisual(MyGrid, layerVisual);
}
The result looks like this.
Remarks
This CompositionEffectBrush cannot take a CompositionBackdropBrush as input, including HostBackdropBrush.