当前位置:编程学习 > C#/ASP.NET >>

WPF,请问动画同步?

第一段动画:

<Grid Height="181" Name="grid1" Width="332" Column="1">
    <Button Content="Button" Height="47" HorizontalAlignment="Center" Name="button1" VerticalAlignment="Center" Width="102">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Width" To="150" Duration="0:0:2" />
                            <DoubleAnimation Storyboard.TargetProperty="Height" To="150" Duration="0:0:2" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
        </Button.Triggers>
    </Button>
</Grid>


第二段动画:

<Window x:Class="WPF熊俊3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WPF熊俊3"
        Title="MainWindow" Height="20" Width="30">
<Window.Triggers>
    <EventTrigger RoutedEvent="Loaded">
        <EventTrigger.Actions>
            <BeginStoryboard>
                <Storyboard>                        
                    <DoubleAnimation Storyboard.TargetProperty="Height" To="441" Duration="0:0:5" />
                    <DoubleAnimation Storyboard.TargetProperty="Width" To="928" Duration="0:0:5" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger.Actions>
    </EventTrigger>
</Window.Triggers>
</Window>



第一段动画,当点击按钮的时候,Width和Height的动画是同时进行的。但是第二段代码,是窗口启动的动画,为什么Width和Height动画没有同步呢?而是Height动画执行完之后,才执行的Width动画? --------------------编程问答-------------------- 都在耍国庆假啊? --------------------编程问答-------------------- 有人知道吗??? --------------------编程问答-------------------- 将两个动画放在一起,然后设置起始时间相同就可以实现。 --------------------编程问答-------------------- 帮你顶下吧。 --------------------编程问答-------------------- BeginTime设成相同的看看。  --------------------编程问答-------------------- 这确实是个很奇怪的问题。
我在stackoverflow上找到的唯一相关的解释:Some of these top level properties on Window are a bit weird and don't behave the same way as other WPF properties because they're on the boundary of Win32.

如果你必须要实现你想要的效果,有两种方法可以尝试。
1. 尝试自已定义依赖属性,关联windows的Height and Width.
2. 不使用Animation,自己用Timer去实现Height and Width的变化。 --------------------编程问答--------------------
引用 5 楼 sjyforg 的回复:
BeginTime设成相同的看看。 

设置相同的BeginTime还是不行。我刚才试了。 --------------------编程问答-------------------- 设置相同的BeginTime还是不行 --------------------编程问答-------------------- 有人知道么... --------------------编程问答-------------------- 顶 --------------------编程问答-------------------- --------------------编程问答-------------------- 有人知道吗?、? --------------------编程问答-------------------- 我试了一下你第二段代码,动画的时候是同步的,不过要把"Loaded"改成"Window.Loaded",否则编译不过去。 --------------------编程问答-------------------- mark....有点奇怪的说。。 关注 --------------------编程问答--------------------  - -~~~尝试了个比较简陋的方法。。
    <Grid Width="100" Height="100" x:Name="xx" SizeChanged="xx_SizeChanged_1">
        <Grid.Triggers>
            <EventTrigger RoutedEvent="Window.Loaded">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Width" To="900" Duration="0:0:5" BeginTime="0:0:0" FillBehavior="HoldEnd" AutoReverse="False" />
                            <DoubleAnimation Storyboard.TargetProperty="Height" To="500" Duration="0:0:5" BeginTime="0:0:0" FillBehavior="HoldEnd" AutoReverse="False"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
        </Grid.Triggers>
    </Grid>


在sizeChanged事件里面去改window的宽高,不过会有黑边。。哎。。。~~  --------------------编程问答-------------------- 帮顶........... --------------------编程问答-------------------- 不懂什么动画。。╮(╯▽╰)╭ 网上这方面的教程太少了! --------------------编程问答-------------------- 还有更好的解释吗??
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,