共用方式為


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。

適用於