silverlight动画不工作

发布于 2024-12-04 12:50:20 字数 1678 浏览 0 评论 0原文

这是我第一次创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑白记忆 2024-12-11 12:50:20

删除情节提要中的 BeginTime 声明或将其更改为其他值(例如 0:0:1)。

值为 1 表示动画应在一小时后开始,将其设置为 0:0:1,将在 1 秒后开始动画。

当加载 MainPage 并将其添加到可视化树时,还要启动动画,如下所示。

public MainPage(){
  InitializeComponent();
  this.Loaded += new System.Windows.RoutedEventHandler(MainPage_Loaded);
}

private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e){
  Storyboard1.Begin();
}

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..

public MainPage(){
  InitializeComponent();
  this.Loaded += new System.Windows.RoutedEventHandler(MainPage_Loaded);
}

private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e){
  Storyboard1.Begin();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文