|
wpf中如果想要使用openFileDialog,
需要引用using Microsoft.Win32;
而不是using System.Windows.Forms;
显示对话框的时候使用ShowDialog()
判断按钮点击,用ture和false,示例代码如下:
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Title = "选择文件";
openFileDialog.Filter = "rcf文件|*.rcf|rcf文件|*.rcf|所有文件|*.*";
openFileDialog.FileName = string.Empty;
openFileDialog.FilterIndex = 1;
openFileDialog.RestoreDirectory = true;
openFileDialog.DefaultExt = "rcf";
if (false == openFileDialog.ShowDialog())
{
return;
}
其实呢,问题就是wpf里面没有现成的这个函数,这个应该是直接调用win32api了。
|
|