silverlight动画不工作
这是我第一次创建 silverlight 动画。在过去的几天里,我一直在努力创建一个简单的动画,但我无法让它发挥作用。我不敢相信为什么这么难。
Xaml:
<UserControl x:Class="BuzzLifeAppsSilverlight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Storyboard x:Name="Storyboard1" AutoReverse="True" RepeatBehavior="Forever" BeginTime="1">
<DoubleAnimation Duration="0:0:2" To="-332" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="button1" d:IsOptimized="True"/>
<DoubleAnimation Duration="0:0:2" To="-12" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="button1" d:IsOptimized="True"/>
</Storyboard>
</UserControl.Resources>
<Canvas x:Name="LayoutRoot" Background="White">
<Button Canvas.Left="235" Canvas.Top="136" Content="Button" Height="23" Name="button1" Width="75" RenderTransformOrigin="0.5,0.5" >
<Button.RenderTransform>
<CompositeTransform/>
</Button.RenderTransform>
</Button>
</Canvas>
</UserControl>
代码:
public MainPage()
{
InitializeComponent();
Storyboard1.Begin();
}
This is the first time I am creating a silverlight animation. I have been struggling to create a simple animation for the last few days I just couldn't get it to work. I can't believe why it is so difficult.
Xaml:
<UserControl x:Class="BuzzLifeAppsSilverlight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Storyboard x:Name="Storyboard1" AutoReverse="True" RepeatBehavior="Forever" BeginTime="1">
<DoubleAnimation Duration="0:0:2" To="-332" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="button1" d:IsOptimized="True"/>
<DoubleAnimation Duration="0:0:2" To="-12" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="button1" d:IsOptimized="True"/>
</Storyboard>
</UserControl.Resources>
<Canvas x:Name="LayoutRoot" Background="White">
<Button Canvas.Left="235" Canvas.Top="136" Content="Button" Height="23" Name="button1" Width="75" RenderTransformOrigin="0.5,0.5" >
<Button.RenderTransform>
<CompositeTransform/>
</Button.RenderTransform>
</Button>
</Canvas>
</UserControl>
Code:
public MainPage()
{
InitializeComponent();
Storyboard1.Begin();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除情节提要中的 BeginTime 声明或将其更改为其他值(例如 0:0:1)。
值为 1 表示动画应在一小时后开始,将其设置为 0:0:1,将在 1 秒后开始动画。
当加载 MainPage 并将其添加到可视化树时,还要启动动画,如下所示。
Remove the declaration of BeginTime in your storyboard or change it to another value (like 0:0:1).
A value of 1 means that the animation should start in one hour, setting it to 0:0:1, will start the animation after 1 second.
Also start the animation, when the MainPage is loaded and added to the visual tree, like so..