LayerVisual.Effect 属性

定义

获取或设置要应用于 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

属性值

要应用于 LayerVisual 子级的平展表示形式的效果。

示例

此示例演示如何将 GaussianBlurEffect 应用于 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);
}        

结果如下所示。

红色正方形与蓝色方块重叠,应用了模糊效果。

注解

此 CompositionEffectBrush 不能将 CompositionBackdropBrush 作为输入,包括 HostBackdropBrush。

适用于