I have been reading about the best way to open dialogs using PRISM and opening them the MVVM way, however what I have found so far seems to only work with custom dialogs. I'd like to be able to open a CommonOpenFileDialog when a button is clicked but I am very confused how I can do this while adhering to the MVVM pattern.
I can accomplish this using the code behind but I would like to avoid this if possible, but the problem I run into here is how I can then pass the dialog result to the view model from the code behind. Would an EventAggregator be acceptable here?
This is my SelectFolderDialog class which opens the dialog. This is currently called from my views code behind:
public class SelectFolderDialog
{
public string SelectFolder()
{
var folderSelectorDialog = new CommonOpenFileDialog();
folderSelectorDialog.EnsureReadOnly = true;
folderSelectorDialog.IsFolderPicker = true;
folderSelectorDialog.AllowNonFileSystemItems = false;
folderSelectorDialog.Multiselect = false;
folderSelectorDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
folderSelectorDialog.Title = "Select Folder";
folderSelectorDialog.ShowDialog();
string SelectedFolderPath = folderSelectorDialog.FileName;
Console.WriteLine(SelectedFolderPath);
return SelectedFolderPath;
}
}