我使用此代码从左到右为图像设置动画,但我希望将 To="100"设置为窗口宽度 如何在窗口加载或调整大小时更改 DoubleAnimation "To"?
xml:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" ResizeMode="CanResize" WindowState="Normal" WindowStyle="ToolWindow" Loaded="Window_Loaded">
<Window.Resources>
<Storyboard x:Key="PlayAnimation" Storyboard.TargetProperty="(Canvas.Left)">
<DoubleAnimation From="0" Duration="0:0:1" RepeatBehavior="Forever" To="100" />
</Storyboard>
</Window.Resources>
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="1" />
<GradientStop Color="#FF5AC0FF" Offset="0" />
</LinearGradientBrush>
</Grid.Background>
<Canvas>
<Image Cursor="Hand" Height="205" HorizontalAlignment="Left" Margin="74,78,0,0" Name="image2" Source="I:\a.png" Stretch="Fill" VerticalAlignment="Top" Width="200" />
</Canvas>
</Grid>
</Window>
C#代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Storyboard sb = this.FindResource("PlayAnimation") as Storyboard;
Storyboard.SetTarget(sb, this.image2);
sb.Begin();
}