private async void AddImagesFromFile(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog() { Multiselect = true, CheckPathExists = true, Filter = "所有图片 (*.ico;*.gif;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.tif;*.tiff;*.bmp;*.dib;*.rle)|*.ico;*.gif;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.tif;*.tiff;*.bmp;*.dib;*.rle" + "|ICO 图标格式 (*.ico)|*.ico" + "|GIF 可交换的图形格式 (*.gif)|*.gif" + "|JPEG 文件交换格式 (*.jpg;*.jpeg;*.jfif;*.jpe)|*.jpg;*.jpeg;*.jfif;*.jpe" + "|PNG 可移植网络图形格式 (*.png)|*.png" + "|TIFF Tag 图像文件格式 (*.tif;*.tiff)|*.tif;*.tiff" + "|设备无关位图 (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle" + "|文件图标 (*.*)|*.*" }; var showDialog = dialog.ShowDialog().GetValueOrDefault(); if (!showDialog) { return; } _controlManager.SelectNone(); _controlManager.ContinuedAddCount = 0; var imageControls = new List <ImageControl>(dialog.FileNames.Length); if (dialog.FilterIndex == 8) { foreach (var filePath in dialog.FileNames) { try { imageControls.Add(PackageImageToControl(new AnimatedGif { Source = Extentions.GetBitmapFormFileIcon(filePath), Stretch = Stretch.Fill }, new Point(0, 0))); } catch (Exception ex) { App.Log.Error(ex.ToString()); Extentions.ShowMessageBox("无法加载文件的图标!"); } } } else { foreach (var file in dialog.FileNames) { try { var imageSource = await Extentions.GetBitmapImage(file); imageControls.Add(PackageImageToControl(new AnimatedGif { Source = imageSource, Stretch = Stretch.Fill }, new Point(0, 0))); } catch (Exception ex) { App.Log.Error(ex.ToString()); Extentions.ShowMessageBox("不支持此格式的图片!"); } } } _controlManager.AddElements(imageControls); }