質問

I am fairly new to wpf.I want to apply a fade animation on the MainWindow as soon as it is displayed on the screen.Is that possible?Please Help me out

役に立ちましたか?

解決

You can apply StoryBoard on window loaded event to give a fade look to your window. This should work for you -

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

Also you can do it in code behind in window loaded event handler if you don't want to do it in XaML -

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        DoubleAnimation animation = new DoubleAnimation(0, 1, 
                                    (Duration)TimeSpan.FromSeconds(1));
        this.BeginAnimation(UIElement.OpacityProperty, animation);
    } 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top