-2

I have a window with a grid and periodically I need to turn whole screen black.

In order to do that I set grid visibility to hidden:

mainGrid.Visibility = Visibility.Hidden;

then, after one second, I change it back to Visible.

But after setting visibility to hidden, screen doesn't change at all.

I tried UpdateLayout, InvalidateArrange, nithing worked...

How to get the grid to hide and reappear again?

Whole code:

mainGrid.Visibility = Visibility.Hidden;
mainGrid.UpdateLayout();
Thread.Sleep(1000);
mainGrid.Visibility = Visibility.Visible;
mainGrid.UpdateLayout();
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69

1 Answers1

0

Your issue is caused by you telling the UI thread to sleep - no updates will happen in this time. If you need a delay that won't block updates to the screen, use a DispatcherTimer or await Task.Delay().

Peregrine
  • 4,287
  • 3
  • 17
  • 34