简体   繁体   English

用于获取启动路径,应用程序数据路径等的WPF与“ System.Windows.Forms.Application.X”等效吗?

[英]What is the WPF equivalent to “System.Windows.Forms.Application.X” for obtaining startup path, app data path, etc.?

I'm converting a windows forms application to a WPF application. 我正在将Windows窗体应用程序转换为WPF应用程序。 Is there a way to obtain things like, Startup Path, User App Data Path, Common App Data Path, etc. without referencing System.Windows.Forms? 有没有一种方法可以获取诸如Startup Path,User App Data Path,Common App Data Path等内容,而无需引用System.Windows.Forms?

Previously, I used System.Windows.Forms.Application.StartupPath , but the System.Windows.Application.Current object doesn't contain the same information. 以前,我使用System.Windows.Forms.Application.StartupPath ,但是System.Windows.Application.Current对象不包含相同的信息。

You might want to look at System.Environment.GetFolderPath . 您可能需要查看System.Environment.GetFolderPath

The values of the SpecialFolder enum are numerous: SpecialFolder枚举的值很多:

ApplicationData
CommonApplicationData
CommonProgramFiles
Cookies
Desktop
DesktopDirectory
Favorites
History
InternetCache
LocalApplicationData
MyComputer
MyDocuments
MyMusic
MyPictures
Personal
ProgramFiles
Programs
Recent
SendTo
StartMenu
Startup
System
Templates

Is that helpful? 有帮助吗?

this will help 这会有所帮助

for Application.StartupPath use AppDomain.CurrentDomain.BaseDirectory 对于Application.StartupPath使用AppDomain.CurrentDomain.BaseDirectory

http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx http://msdn.microsoft.com/zh-CN/library/system.appdomain.basedirectory.aspx

You can use the Environment class to get all types of system information. 您可以使用Environment类来获取所有类型的系统信息。 For directories, use the Environment.GetFolderPath method. 对于目录,请使用Environment.GetFolderPath方法。

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

I understand and agree that referencing to System.Windows.Forms.dll looks ugly but I think that's better then decrease code re-use and re-invent bicycle instead just one more reference. 我理解并同意,对System.Windows.Forms.dll引用看起来很丑,但我认为最好是减少代码的重复使用并重新发明自行车,而不是再增加一个引用。

I use for example System.Windows.Forms.Application.ProductVersion in my console apps, don't like that but think that's the lesser evil.. 我在控制台应用程序中使用了System.Windows.Forms.Application.ProductVersion例如,不喜欢那样,但是认为这是次要的事情。

See also this question on SO 另请参阅问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM