WPF怎么才能打开文件对话框?如何打开一张图片?
windows应用程序中可以使用openfiledialog类打开文件对话框,但是到WPF里就没有这个类。。。要怎么才能打开文件对话框?如何打开一张图片?
public class FileHepler
{
static private String _imageFilters = "*.jpg;*.png;*.bmp;";
static private String _xpsFilters = "*.xps;";
static private String _rtfFilters = "*.rtf;";
static private String _xampFilters = "*.xamp;";
static public String GetImageFileDlgFilter() { return String.Format("图片文件|{0}{1}{2}{3}|所有文件|*.*", _imageFilters, _xpsFilters, _rtfFilters, _xampFilters); }
}
在导入图片的事件中
private void btnImportBackGroud_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog imageFile = new OpenFileDialog();
imageFile.Filter = FileHelper.GetImageFileDlgFilter();
if (imageFile.ShowDialog() ?? false)
{
........
}
}
希望对你有帮助。我是刚加入的新成员,大家互相帮助。