How can I restart WPF application?

六月ゝ 毕业季﹏ 提交于 2019-12-07 17:29:31

问题


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;

回答1:


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(). `.



来源:https://stackoverflow.com/questions/3634439/how-can-i-restart-wpf-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!