WPF背景颜色变化的动画

2017-11-24 19:36:30来源:CSDN作者:yuhai738639人点击

分享

//想做一个背景颜色变化的动画,开始想用透明因子Opacity来实现,后来发现可以改变渐变线性刷LinearGradienBrush的Offset来实现//就是在设置Storyboard.TargetProperty的时候比较绕//实例:

<Color x:Key="WhiteColor">#FFFFFFFF</Color><Color x:Key="NormalColor">#FF398FDF</Color><LinearGradientBrush x:Key="LGBrush" StartPoint="0,0.5" EndPoint="1,0.5">	<GradientStop Color="{StaticResource NormalColor}" Offset="0"/>	<GradientStop Color="{StaticResource WhiteColor}" Offset="0.5"/>	<GradientStop Color="{StaticResource NormalColor}" Offset="1"/></LinearGradientBrush><Grid>  <Grid.Triggers>    <EventTrigger RoutedEvent="Loaded">	<BeginStoryboard>			<Storyboard> 				<DoubleAnimation Storyboard.TargetName="border" 					Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"					BeginTime="00:00:00" Duration="00:00:10" From="0" To="1" AutoReverse="True" RepeatBehavior="Forever"/>			</Storyboard>		</BeginStoryboard>        </EventTrigger>    </Grid.Triggers>    <Border x:Name="border" Background={StaticResource LGBrush} CornerRadius="2"/></Grid>

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台