dotMorten / WinUIEx

WinUI Extensions
https://dotmorten.github.io/WinUIEx
MIT License
615 stars 40 forks source link

Backdrop stops working after window is hidden using Closed event #55

Closed rocksdanister closed 2 years ago

rocksdanister commented 2 years ago

Bug: Mica/Acrylic backdrop stops working when Window is hidden then shown again using Closed event.

Use case: Application runs UI as a separate WinUI program and has the option to hide the program instead of closing when not in use.

Example to reproduce:

//Closed is closing. 
//ref: https://github.com/microsoft/microsoft-ui-xaml/issues/5454
this.Closed += (s, e) =>
{
    e.Handled = true;
    this.Hide();
};
...
await Task.Delay(2000);
this.Close();
await Task.Delay(2000);
this.Show(); //no backdrop.
await Task.Delay(2000);
this.Hide();
await Task.Delay(2000);
this.Show(); //backdrop 
dotMorten commented 2 years ago

@rocksdanister Thank you for the great error report. I pushed a fix. I'm overhauling the backdrop API quite a lot though to give you more control, and the fix will be in the next update. For now, try setting the backdrop to default and back again to "restore" it right before calling Show.

JasonWei512 commented 2 years ago

@dotMorten I have the exact same problem in v1.8.0. To workaround this bug I have to set Window.Backdrop to new MicaSystemBackdrop() after calling Show().

dotMorten commented 2 years ago

@JasonWei512 Could you provide a repro? The above repro was used to verify the fix.

JasonWei512 commented 2 years ago

Reproduction: https://github.com/JasonWei512/WinUIExMicaBackdropBug

MainWindow.Closed += (sender, args) => 
{
    args.Handled = true;
    MainWindow.Hide();
};

// Mica backdrop effect will disappear
MainWindow.Close();
await Task.Delay(TimeSpan.FromSeconds(1));
MainWindow.Show();

// Workaround
MainWindow.Close();
await Task.Delay(TimeSpan.FromSeconds(1));
MainWindow.Show();
MainWindow.Backdrop = new MicaSystemBackdrop();