Program isn't retrieving from taskbar after minimizing it

后端 未结 1 864
花落未央
花落未央 2021-01-22 18:36

I\'ll give some background about what I am trying to do:

I have created a customized button that should minimize my window with a fade out animation so here\'s the code

相关标签:
1条回答
  • 2021-01-22 18:45

    Try using another animation to set the opacity back to 1:

        private void set_Opacity(object sender, EventArgs e)
        {
            var anim = new DoubleAnimation(1, (Duration)TimeSpan.FromSeconds(0));
            this.BeginAnimation(UIElement.OpacityProperty, anim);
        }
    

    EDIT: the reason why this approach works and simply setting the opacity to 1 doesn't is due to dependency property value setting precedence. In short, values set by animations take priority over 'local' values set, i.e. those values set by assigning to the property.

    In your case, the animation had finished, but it was still 'holding on' to the Opacity dependency property. However, if you create your fading-out animation with

        anim.FillBehavior = FillBehavior.Stop;
    

    then the animation will 'release' the Opacity property once it finishes and you don't then need another animation to set it back to 1. Your original set_Opacity method should then work.

    Note also that you shouldn't assign WindowState = WindowState.Normal in your set_Opacity method. If you maximize the window, click your button to minimize it, and then click on the taskbar button, the window doesn't reappear maximized.

    0 讨论(0)
提交回复
热议问题