public Task <string> ShowOpenFileDialogAsync(string title, string defaultExtension, params Tuple <string, string>[] extensions) { var tcs = new TaskCompletionSource <string>(); _dispatcherService.CurrentDispatcher.BeginInvoke(new Action(() => { var result = string.Empty; CommonOpenFileDialog cfd = new CommonOpenFileDialog { AllowNonFileSystemItems = true, EnsureReadOnly = true, EnsurePathExists = true, EnsureFileExists = true, DefaultExtension = defaultExtension, Multiselect = false, // One file at a time Title = title ?? I18N.GetSplitString("Select File") }; if ((extensions != null) && (extensions.Any())) { foreach (var ext in extensions) { cfd.Filters.Add(new CommonFileDialogFilter(ext.Item1, ext.Item2)); } } if (cfd.ShowDialog() == CommonFileDialogResult.Ok) { ShellObject selectedObj = null; try { // Try to get the selected item selectedObj = cfd.FileAsShellObject; } catch { //MessageBox.Show("Could not create a ShellObject from the selected item"); } if (selectedObj != null) { // Get the file name result = selectedObj.ParsingName; } } tcs.SetResult(result); })); return(tcs.Task); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var status = (Status?)value ?? Status.Busy; var resolveType = parameter as string; if (resolveType == "TrayIcon") { switch (status) { case Status.Ready: return("/Resources/Icons/TrayIcons/Ready.ico"); case Status.Disabled: return("/Resources/Icons/TrayIcons/Disabled.ico"); default: return("/Resources/Icons/TrayIcons/Busy.ico"); } } if (resolveType == "ToolTipImage") { switch (status) { case Status.Ready: return("/Resources/Images/TrayIcons/Ready.png"); case Status.Disabled: return("/Resources/Images/TrayIcons/Disabled.png"); default: return("/Resources/Images/TrayIcons/Busy.png"); } } if (resolveType == "ToolTipText") { return($"{I18N.GetSplitString("Current status is :")} {I18N.GetString(status.ToString("G"))}"); } return(Binding.DoNothing); }