问题描述
我第一次在WPF实现的FolderBrowserDialog,我没有从我已经搞清楚了Windows中的问题,爱它一个位...
除了者,恕不不是在我的项目中引用,我现在遇到了麻烦想看看有什么DialogResult的返回值是...
通过一个OpenFileDialog,在过去的我正是如此做的:
打开文件对话框OFD =新的OpenFileDialog();
可空<布尔>结果= ofd.ShowDialog();
如果(结果==真)
{
//一切顺利,继续在这里做你的事
}
不幸的是,现在我得到错误与这句话有关的东西从转换类型的DialogResult为bool和任何有你。
似乎无法找到如何完成在使用WPF对话框这一步任何事情,任何人都可以提供一些线索?
提前感谢!
修改
下面的修订没有我的代码类型转换错误。我不知道要检查结果
反对什么价值。通常,我会使用 DialogResult.OK
除了不会出现在这里作为一个有效的值。
私人无效btnBrowse_Click(对象发件人,RoutedEventArgs E)
{
如果(cmbTemplate.SelectedItem ==大片)
{
的FolderBrowserDialog FBD =新的FolderBrowserDialog();
DialogResult的结果= fbd.ShowDialog();
//
//错误:System.Nullable<布尔>'不包含'OK'
//没有延伸的方法定义'OK'接受类型
//的第一个参数System.Nullable<布尔>'可以找到。
//
如果(结果== DialogResult.OK)
{
txtSource.Text = fbd.SelectedPath;
}
}
}
好了,原来所有的答案其他的答案在这里是正确的。
他们只是错过了一件事,我认为这是我的错...
每当我看到试图利用它在我的if语句(因为我已经被告知,当的DialogResult
在IntelliSense使用时,我看到了这一点:
This particular DialogResult object isn't the one I was looking for.
What finally worked was the following:
DialogResult result = fbd.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
// do work here
}
It's worth noting that I do have System.Windows.Forms
referenced in my usings which is why I never thought to reference the class from System as in the above snippet. I thought it was using this anyway.
这篇关于在与WPF的FolderBrowserDialog的DialogResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!