DropShadow 类

定义

public ref class DropShadow sealed : CompositionShadow
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.LiftedContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DropShadow final : CompositionShadow
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65536)]
class DropShadow final : CompositionShadow
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.LiftedContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class DropShadow : CompositionShadow
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65536)]
public sealed class DropShadow : CompositionShadow
Public NotInheritable Class DropShadow
Inherits CompositionShadow
继承
Object Platform::Object IInspectable CompositionObject CompositionShadow DropShadow
属性

示例

简单 DropShadow

private async void InitComposition()
{
  _compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;
  _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);

  //Create surface brush and load image
  CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush();
  surfaceBrush.Surface = await _imageLoader.LoadImageFromUriAsync(new Uri("ms-appx:///Assets/cat.jpg"));

  //Create sprite visual
  SpriteVisual visual = _compositor.CreateSpriteVisual();
  visual.Brush = surfaceBrush;
  visual.Size = new Vector2(270, 200);

  //Create drop shadow
  DropShadow shadow = _compositor.CreateDropShadow();
  shadow.BlurRadius = 5;
  shadow.Offset = new Vector3(15, 15, -10);
  shadow.Color = Colors.DarkGray;

  //Associate shadow with visual
  visual.Shadow = shadow;
}         

具有动画的 DropShadow

private async void InitComposition()
{
  _compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;
  _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);

  //Create surface brush and load image
  CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush();
  surfaceBrush.Surface = await _imageLoader.LoadImageFromUriAsync(new Uri("ms-appx:///Assets/cat.jpg"));

  //Create sprite visual
  SpriteVisual visual = _compositor.CreateSpriteVisual();
  visual.Brush = surfaceBrush;
  visual.Size = new Vector2(270, 200);

  //Create drop shadow
  DropShadow shadow = _compositor.CreateDropShadow();
  shadow.BlurRadius = 5;
  shadow.Offset = new Vector3(15, 15, -10);
  shadow.Color = Colors.DarkGray;

  //Create animations
  ScalarKeyFrameAnimation blurAnimation = this.CreateBlurAnimation();
  Vector3KeyFrameAnimation offsetAnimation = this.CreateOffsetAnimation();

  //Apply animations
  shadow.StartAnimation("BlurRadius", blurAnimation);
  shadow.StartAnimation("Offset", offsetAnimation);

  //Associate shadow with visual
  visual.Shadow = shadow;
}

private ScalarKeyFrameAnimation CreateBlurAnimation()
{
  ScalarKeyFrameAnimation shadowBlurAnimation = _compositor.CreateScalarKeyFrameAnimation();
  shadowBlurAnimation.InsertKeyFrame(0.0f, 5.0f);
  shadowBlurAnimation.InsertKeyFrame(0.5f, 20.0f);
  shadowBlurAnimation.InsertKeyFrame(1.0f, 5.0f);
  shadowBlurAnimation.Duration = TimeSpan.FromSeconds(2);
  shadowBlurAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

  return shadowBlurAnimation;
}

private Vector3KeyFrameAnimation CreateOffsetAnimation()
{
  Vector3 startOffset = new Vector3(15, 15, -10);
  Vector3 endOffset = new Vector3(30, 30, -20);

  Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation();
  offsetAnimation.InsertKeyFrame(0.0f, startOffset);
  offsetAnimation.InsertKeyFrame(0.5f, endOffset);
  offsetAnimation.InsertKeyFrame(1.0f, startOffset);
  offsetAnimation.Duration = TimeSpan.FromSeconds(2);
  offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever;

  return offsetAnimation;
}         

DropShadow 使用 CompositionDropShadowSourcePolicy 从视觉对象的画笔继承 alpha

private async void InitComposition()
{
  _compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor;

  //Create surface brush and load image
  CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush();
  surfaceBrush.Surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/circle.png"));

  //Create sprite visual
  SpriteVisual visual = _compositor.CreateSpriteVisual();
  visual.Brush = surfaceBrush;
  visual.Size = new Vector2(270, 200);

  //Create drop shadow
  DropShadow shadow = _compositor.CreateDropShadow();
  shadow.BlurRadius = 5;
  shadow.Offset = new Vector3(15, 15, -10);
  shadow.Color = Colors.DarkGray;

  //Specify mask policy for shadow
  shadow.SourcePolicy = CompositionDropShadowSourcePolicy.InheritFromVisualContent;

  //Associate shadow with visual
  visual.Shadow = shadow;
}         

注解

DropShadow 是在应用程序 UI 中提供深度指示的常用方法。 若要添加 DropShadow,请创建 DropShadow 的实例并使用 附加它。 SpriteVisualLayerVisual 上的 Shadow 属性。

阴影不会由视觉对象 (上的隐式剪辑集根据视觉对象) 的大小进行剪裁。 但是,阴影遵循使用 SpriteVisual.Clip 属性在视觉对象上设置的显式剪辑。

属性

BlurRadius

用于生成阴影的高斯模糊的半径。 可动画处理。

Color

阴影的颜色。 可动画处理。

Comment

要与 CompositionObject 关联的字符串。

(继承自 CompositionObject)
Compositor

用于创建此 CompositionObject 的 Compositor

(继承自 CompositionObject)
DispatcherQueue

获取 CompositionObject 的 DispatcherQueue。

(继承自 CompositionObject)
ImplicitAnimations

附加到此对象的隐式动画集合。

(继承自 CompositionObject)
Mask

用于为阴影指定不透明度掩码的画笔。 默认为 SpriteVisual 的画笔。 可动画处理。

Offset

阴影相对于其 SpriteVisual 的偏移量。 可动画处理。

Opacity

阴影的不透明度。 可动画处理。

Properties

CompositionObject 关联的属性的集合。

(继承自 CompositionObject)
SourcePolicy

用于定义要用于阴影的阴影掩码策略。

方法

Close()

关闭 CompositionObject 并释放系统资源。

(继承自 CompositionObject)
Dispose()

执行与释放或重置非托管资源关联的应用程序定义的任务。

(继承自 CompositionObject)
PopulatePropertyInfo(String, AnimationPropertyInfo)

定义可进行动画处理的属性。

(继承自 CompositionObject)
StartAnimation(String, CompositionAnimation, AnimationController)

使用 对象的指定属性连接动画并启动动画。

(继承自 CompositionObject)
StartAnimation(String, CompositionAnimation)

使用 对象的指定属性连接动画并启动动画。

(继承自 CompositionObject)
StartAnimationGroup(ICompositionAnimationBase)

启动动画组。

CompositionObject 上的 StartAnimationGroup 方法可用于启动 CompositionAnimationGroup。 组中的所有动画将同时在 对象上启动。

(继承自 CompositionObject)
StopAnimation(String)

断开动画与指定属性的连接并停止动画。

(继承自 CompositionObject)
StopAnimationGroup(ICompositionAnimationBase)

停止动画组。

(继承自 CompositionObject)
TryGetAnimationController(String)

返回指定属性上运行的动画的 AnimationController。

(继承自 CompositionObject)

适用于

另请参阅