1

我对 wpf 很陌生。我想在 MainWindow 上应用淡入淡出动画,一旦它显示在屏幕上。这可能吗?请帮帮我

4

1 回答 1

9

您可以应用StoryBoard窗口loaded事件来为您的窗口提供淡入淡出的外观。这应该适合你 -

<Window.Triggers>
    <EventTrigger RoutedEvent="Window.Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation Storyboard.TargetProperty="(Window.Opacity)"
                                 From="0.0" To="1.0" Duration="0:0:1"
                                 AutoReverse="False"/>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Window.Triggers>

loaded如果您不想在 XaML 中执行此操作,您也可以在窗口事件处理程序后面的代码中执行此操作 -

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        DoubleAnimation animation = new DoubleAnimation(0, 1, 
                                    (Duration)TimeSpan.FromSeconds(1));
        this.BeginAnimation(UIElement.OpacityProperty, animation);
    } 
于 2013-04-06T19:23:30.000 回答