Prevent the user from using the mainwindow window while another window is open

Asked

Viewed 186 times

0


I have a WPF application following the MVVM standard and in a certain part of the application I show a Progressbar that I implemented in a separate view for the user and, while this progressionBar is running, I would need the user to be unable to move in any other window, just as the "Showdialog()" method does however, if I display progression Using Showdialog() the main app stops doing the process as it waits for the Result of my view...

inserir a descrição da imagem aqui

Here’s the part of the Code I call progress

_progressBar = new PackProgressBar("Packing",BasicVariableCollection.Count - 1);
_progressBar.Show();

Where "Packprogressbar" is the name of my Progressibar View class, which is from the "Window" class"

  • 1

    Maybe you can work with Threads. The process runs on a separate thread while the main thread is only responsible for working the events in your program windows. This approach is the most recommended when we have jobs that should be performed in the background but should not paralyze window responses. I usually work c/ Backgroundworker on Winforms, but apparently good practices for WPF say p/ use a Threading modeling on the application, see the MSDN reference: https://docs.microsoft.com/pt-br/dotnet/workframewpf/advanced/threading-model

2 answers

0

You must use Form.ShowDialog.

ShowDialog()method instead of Show()when you display the child form.

  • The "Showdialog()" method causes the method to be "Locked" until it has a Result, and so my "Longrunningprocess" hangs and does not proceed

0


I was able to come up with a solution to the problem, using the mainwindow’s "Isenabled" property thus setting this proprierdade to "false" when calling the progressibar and then to "true" in the asynchronous task’s Runworkercompleted

 _progressBar = new PackProgressBar("Packing", BasicVariableCollection.Count - 1);
 _progressBar.Show();
 System.Windows.Application.Current.MainWindow.IsEnabled = false;

and

System.Windows.Application.Current.MainWindow.IsEnabled = true;
_progressBar.Close();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.