Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I restart WPF application?

Tags:

wpf

How can I restart WPF application from code? in Windows Forms there is Application.Restart, where for whatever reason Microsoft decided not to add this method in WPF.

I hate the discompatability between WPF and WindowsForms! like:

            window.Visibility = System.Windows.Visibility.Hidden;

What's wrong with that?

            window. Visible = false;
like image 919
Mark Avatar asked Feb 03 '26 14:02

Mark


1 Answers

Visibility

For controls and panels, there is a huge difference between Visibility.Collapsed and Visiblity.Hidden. Hidden reserves the space of the invisible element, Collapse frees the used space. This can make a big difference in an UI.

Using the same enumeration for the visibility of the window-class is IMO first of all a question of holding a constancy in the class-library, but may be it makes also some other finer differences.

Restart

If there is a possibility to directly restart the app, I don't know. What you can try is to use App.Current.Shutdown() to close the app and start a new instance through System.Diagnostics.Process.Start() where the path to the app can be taken from System.Reflection.Assembly.GetEntryAssembly(). `.

like image 141
HCL Avatar answered Feb 05 '26 07:02

HCL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!