弹来弹去跑马灯!

UWP Shadow 阴影

参考文字: https://mtaulty.com/2016/08/10/windows-10-uwp-and-composition-light-and-shade/

 

<Grid
  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Grid
      x:Name="grid" />
    <TextBlock
      x:Name="txtBlock"
      Text="Drop Shadow"
      FontSize="48"
      HorizontalAlignment="Center"
      VerticalAlignment="Center" />
  </Grid>
</Grid>

  

var compositor = ElementCompositionPreview.GetElementVisual(this.grid).Compositor;
var spriteVisual = compositor.CreateSpriteVisual();
spriteVisual.Size = this.grid.RenderSize.ToVector2();
 
var dropShadow = compositor.CreateDropShadow();
dropShadow.Mask = this.txtBlock.GetAlphaMask();
dropShadow.Offset = new Vector3(10, 10, 0);
spriteVisual.Shadow = dropShadow;
 
ElementCompositionPreview.SetElementChildVisual(this.grid, spriteVisual);

  

 

posted @ 2020-09-15 18:06  wgscd  阅读(350)  评论(0编辑  收藏  举报