Search code examples
c#savefiledialogavaloniaui

Avalonia UI's OpenFileDialog and SaveFileDialog - How to detect a cancel button being clicked


With the code here to open a SaveFileDialog, how would I detect if the user presses cancel?

     SaveFileDialog SaveFileBox = new SaveFileDialog();
     SaveFileBox.Title = "Save Document As...";
     SaveFileBox.InitialFileName = Path.GetFullPath(DocumentFileName);
     SaveFileBox.Directory = workdir;
     List<FileDialogFilter> Filters = new List<FileDialogFilter>();
     FileDialogFilter filter = new FileDialogFilter();
     List<string> extension = new List<string>();
     extension.Add("doc");
     filter.Extensions = extension;
     filter.Name = "Document Files";
     Filters.Add(filter);
     SaveFileBox.Filters = Filters;

     SaveFileBox.DefaultExtension = "doc";

     SettingsFileName = await SaveFileBox.ShowAsync(this);

thank you in advance!!


Solution

  • The return value from ShowAsync will be null or an empty array.