gpt4 book ai didi

c# - 动画绘图Image GeometryDrawing Wpf Xaml

转载 作者:太空宇宙 更新时间:2023-11-03 12:48:50 25 4
gpt4 key购买 nike

我有一个 UserControl 并且想要为 GeometryDrawing 对象之一设置动画。在我的例子中,有一个“circle1”,我想无限旋转。有人可以帮我吗( Storyboard?我应该在哪里放置 xaml 代码?)?谢谢。

<UserControl.Resources>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sch.microsoft.com/winfx/2006/xaml">
<DrawingImage x:Key="PumpOn">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry="F1 M 214.557,193.691L 109.3,11.3306L 4,193.666L 214.557,193.691 Z ">
<GeometryDrawing.Pen>
<Pen LineJoin="Round" Brush="#FF00C800"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Brush>
<LinearGradientBrush StartPoint="-0.00237454,0.5" EndPoint="1.00237,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FF46FF00" Offset="0"/>
<GradientStop Color="#FFD6FFC5" Offset="0.5"/>
<GradientStop Color="#FF46FF00" Offset="0.991379"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>
<GeometryDrawing x:Name="circle1" Geometry="F1 M 109.604,10.0258C 177.463,10.0258 232.474,65.0365 232.474,132.896C 232.474,200.755 177.463,255.765 109.604,255.765C 41.7451,255.765 -13.2656,200.755 -13.2656,132.896C -13.2656,65.0365 41.745,10.0258 109.604,10.0258 Z ">
<GeometryDrawing.Pen>
<Pen Thickness="2" LineJoin="Round">
<Pen.Brush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF5DFF00" Offset="0"/>
<GradientStop Color="#FF8D8D8D" Offset="0.448"/>
</LinearGradientBrush>
</Pen.Brush>
</Pen>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</ResourceDictionary>

</UserControl.Resources>

最佳答案

您可以使用 ColorAnimation 来执行以下操作:

<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="myImage" Storyboard.TargetProperty="Source.Drawing.Children[1].Pen.Brush.GradientStops[0].Color" To="#FF8D8D8D" Duration="0:0:0.5" AutoReverse="True"
RepeatBehavior="Forever"></ColorAnimation>
<ColorAnimation Storyboard.TargetName="myImage" Storyboard.TargetProperty="Source.Drawing.Children[1].Pen.Brush.GradientStops[1].Color" To="#FF5DFF00" Duration="0:0:0.5" AutoReverse="True"
RepeatBehavior="Forever"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid>
<Image x:Name="myImage">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry="F1 M 214.557,193.691L 109.3,11.3306L 4,193.666L 214.557,193.691 Z ">
<GeometryDrawing.Pen>
<Pen LineJoin="Round" Brush="#FF00C800"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Brush>
<LinearGradientBrush StartPoint="-0.00237454,0.5" EndPoint="1.00237,0.5">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FF46FF00" Offset="0"/>
<GradientStop Color="#FFD6FFC5" Offset="0.5"/>
<GradientStop Color="#FF46FF00" Offset="0.991379"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>
<GeometryDrawing x:Name="circle1" Geometry="F1 M 109.604,10.0258C 177.463,10.0258 232.474,65.0365 232.474,132.896C 232.474,200.755 177.463,255.765 109.604,255.765C 41.7451,255.765 -13.2656,200.755 -13.2656,132.896C -13.2656,65.0365 41.745,10.0258 109.604,10.0258 Z ">
<GeometryDrawing.Pen>
<Pen Thickness="2" LineJoin="Round">
<Pen.Brush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF5DFF00" Offset="0"/>
<GradientStop Color="#FF8D8D8D" Offset="0.448"/>
</LinearGradientBrush>
</Pen.Brush>
</Pen>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Grid>

关于c# - 动画绘图Image GeometryDrawing Wpf Xaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36326035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com