I'm trying to make a fancy blinking icon and animate the brush of a GeometryDrawing and can not figure out how to do this. Is it possible?
Here is some base xaml
<Window.Resources>
<GeometryDrawing x:Key="_geometryTest" Brush="#FF6C897B" Geometry="F1 M 66,188L 194,60L 322,188L 250.889,188L 250.889,348L 137.111,348L 137.111,188L 66,188 Z ">
<GeometryDrawing.Pen>
<Pen LineJoin="Round" Brush="#FF000000"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</Window.Resources>
<Grid>
<Image>
<Image.Source>
<DrawingImage x:Name="_myImage" Drawing="{Stati开发者_运维技巧cResource _geometryTest}"/>
</Image.Source>
</Image>
</Grid>
Use a ColorAnimation
for it. This example will start the animation when the Window
is loaded
<Window.Resources>
<GeometryDrawing x:Key="_geometryTest"
Brush="#FF6C897B"
Geometry="F1 M 66,188L 194,60L 322,188L 250.889,188L 250.889,348L 137.111,348L 137.111,188L 66,188 Z">
<GeometryDrawing.Pen>
<Pen LineJoin="Round" Brush="#FF000000"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="myImage"
Storyboard.TargetProperty="(Image.Source).(DrawingImage.Drawing).(GeometryDrawing.Brush).(SolidColorBrush.Color)"
To="Red"
Duration="0:0:0.5"
AutoReverse="True"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid>
<Image Name="myImage">
<Image.Source>
<DrawingImage x:Name="_myImage" Drawing="{StaticResource _geometryTest}"/>
</Image.Source>
</Image>
</Grid>
精彩评论