FolderBrowserDialog in wpf c#

删除回忆录丶 提交于 2019-12-07 09:16:16

问题


I am using System.Windows; and System.Windows.Controls; so I can't use System.Windows.Forms; because there is a lot of controls like messagebox and list box...etc are common between them is there another solution to get folderbrowserdialog without using System.Windows.Forms; or is there any get folder location dialog box ?


回答1:


You can use the FolderBrowserDialog; either explicitly place the namespace in front of the class...

System.Windows.Forms.FolderBrowserDialog browse = new System.Windows.Forms.FolderBrowserDialog();

...or create an alias with regard to your namespace.

Imports [ aliasname = ] namespace



回答2:


I have also encountered this using FolderBrowserDialog in WPF with listBox.

because we use WPF, we need to add winform component "FolderBrowserDialog".

  • right click on the project name or reference, and choose "Add reference"
  • choose .Net tab and browse for System.Windows.Forms.

So now you can use FolderBrowserDialog in WPF.

private FolderBrowserDialog openFolder = new FolderBrowserDialog();

Here is a link to a post on my blog that contains the image and a short explanation http://syumulnetwork.blogspot.com/2011/09/myth-self-note-5-c-wpf.html




回答3:


See my answer to Select folder dialog WPF for some example code. Basically the Windows Presentation Foundation 4.5 Cookbook recommends that you use the Windows® API Code Pack for Microsoft® .NET Framework if you need a folder browser.



来源:https://stackoverflow.com/questions/6630847/folderbrowserdialog-in-wpf-c-sharp

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