/// <summary> /// Load From File Click Event /// </summary> /// <param name="sender">Sender Object</param> /// <param name="e">Routed Event Argument</param> private void LoadFromFileClick(object sender, RoutedEventArgs e) { try { var view = AppContext.ActiveView as ViewImage; if (view != null) { Imaging imageData = view.GetImagingData(); if (imageData != null) { ImageMetaData imageMetaData = imageData.MetaData; if (imageMetaData != null) { // get the filename (and path) with the common dialog var loadFileDialog = new CommonDialog(); var filter = new FilterEntry(Strings.XmlFileDescription, Strings.XmlFileExtension); loadFileDialog.Filters.Add(filter); loadFileDialog.ShowOpen(); string fileName = loadFileDialog.FileName; if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) { return; } // read the meta data imageMetaData.ReadFromXml(fileName); } } } } catch (Exception ex) { Util.ReportException(ex); } }
/// <summary> /// Event Handler for clicking image path button /// </summary> /// <param name="sender">sender object</param> /// <param name="e">routed event args</param> private void ImagePathBtnClick(object sender, RoutedEventArgs e) { try { // 1) Open File Dialog with wiff/img filter string fileName = string.Empty; var openFileDialog = new CommonDialog(); if (AppContext.SpecFileLoaders != null && AppContext.SpecFileLoaders.Count > 0) { foreach (ISpecFileLoader loader in AppContext.SpecFileLoaders) { FileTypeDescriptorList supportedFileTypes = loader.SupportedFileTypes; if (supportedFileTypes != null) { foreach (FileTypeDescriptor fileType in supportedFileTypes) { if (fileType.Extensions != null) { foreach (string extension in fileType.Extensions) { var filter = new FilterEntry(fileType.Description, extension); openFileDialog.Filters.Add(filter); } } } } } // proceed if at least one loader is ready to accept a file... if (openFileDialog.Filters.Count > 0) { // Add the all files filter openFileDialog.Filters.Add(new FilterEntry(Strings.AllFilesDesc, Strings.AllFilesExt)); openFileDialog.ShowOpen(); fileName = openFileDialog.FileName; } } if (!string.IsNullOrEmpty(fileName) || File.Exists(fileName)) { // 2) Update ImagePathTB.Text = fileName; } } catch (Exception ex) { Util.ReportException(ex); } }