效果图:
实现思路:
通过TextBlock.Clip设置EllipseGeometry来实现聚光的效果;
添加动画使其移动;
最后添加相同TextBlock作为背景。
思路参考于收费大佬,欢迎点赞与交流哦!!!
代码实现:
<Canvas>
<TextBlock Text="🐱🐉聚光灯照亮😂" FontSize="64" FontWeight="ExtraLight">
<TextBlock.Foreground>
<LinearGradientBrush SpreadMethod="Repeat" StartPoint="0,0" EndPoint="1,0">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.00" Color="LawnGreen"/>
<GradientStop Offset="0.25" Color="GreenYellow"/>
<GradientStop Offset="0.50" Color="Yellow"/>
<GradientStop Offset="0.75" Color="SkyBlue"/>
<GradientStop Offset="1.00" Color="DeepSkyBlue"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
<TextBlock Text="🐱🐉聚光灯照亮😂" FontSize="64" FontWeight="ExtraLight" Foreground="Red">
<TextBlock.Clip >
<GeometryGroup>
<EllipseGeometry RadiusX="42" RadiusY="42" Center="-38,42">
<EllipseGeometry.Transform>
<TranslateTransform x:Name="TranslateTransform"/>
</EllipseGeometry.Transform>
</EllipseGeometry>
</GeometryGroup>
</TextBlock.Clip>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetName="TranslateTransform" Storyboard.TargetProperty="X" From="0" To="600" Duration="0:0:5" BeginTime="0:0:1"/>
<DoubleAnimation Storyboard.TargetName="TranslateTransform" Storyboard.TargetProperty="X" From="600" To="0" Duration="0:0:5" BeginTime="0:0:7"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
</Canvas>