注册 登录
编程论坛 WPF/Silverlight

WPF怎么才能打开文件对话框?如何打开一张图片?

绽放的凌霄 发布于 2012-12-08 16:47, 6095 次点击
windows应用程序中可以使用openfiledialog类打开文件对话框,但是到WPF里就没有这个类。。。要怎么才能打开文件对话框?如何打开一张图片?
1 回复
#2
xianglovelin2012-12-20 09:43
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)
            {
             ........
            }
        }
希望对你有帮助。我是刚加入的新成员,大家互相帮助。
1