2013-10-23 100 views
0

我需要在我的WPF应用程序中使用FolderBrowser来选择包含图像的文件夹。我知道System.Windows.Forms版本,但它使MessageBox含糊不清,这使得难以向我的用户显示其他消息。有没有不同的方式来做到这一点,或者我应该使用自定义控件。还是有办法摆脱模棱两可的错误?实现文件夹浏览器

+0

什么模糊错误? – Lloyd

+0

http://tyburnfolderbrowsers.codeplex.com/ –

+0

或[Windows 7 API代码包](http://archive.msdn.microsoft.com/WindowsAPICodePack)中的'CommonOpenFileDialog'。只需将'IsFolderPicker'属性设置为true即可。看起来好多了。 – Clemens

回答

3

就进口形式:

using Forms = System.Windows.Forms; 

然后,当你想创建一个文件夹对话框,你可以这样写:

Forms.FolderBrowserDialog dlg = new Forms.FolderBrowserDialog(); 

这应该摆脱模糊性。

+0

谢谢你工作完美 – daJbot

0

WinForms的MessageBox位于不同的名称空间中。因此,如果您的源代码文件开头的名称空间都有using(对于Forms,则为System.Windows.Forms,对于WPF为Systems.Windows),则必须在两个名称空间中访问具有相同名称的类时提供完整名称空间。

using System.Windows; 
using System.Windows.Forms; 

[...] 
public void MyFunction() 
{ 
    System.Windows.Forms.MessageBox.Show("Hello, World!"); 
} 
0

由于暧昧的错误发生,因为2个或更多的东西具有相同的名称和签名,您只需调用的MessageBox绕过它时更加具体。

blah.blah.MessageBox("message"); 

代替

MessageBox("message"); 
0

不要把System.Windows.Formsusing,使您避免暧昧MessageBox

public bool SelectDirectory(out String directoryName) 
{ 
    System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog(); 
    directoryName = String.Empty; 
    dlg.SelectedPath = String.Empty; 
    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
    { 
     directoryName = dlg.SelectedPath; 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 

只需包含此方法并在其他地方继续使用WPF。