I've often come across this but after working on a long project, often forget the basics - as in using Dialog boxes for File operations. The stanard error is "Dialogs must be user-initiated" which is a little off from the point - you'd expect that a click event could also open a dialog however it is because the threading (context) of the Dialog would be lost in the event.
The solution is simple - simply put all of the Dialog logic in its own method and call the method from the click event:
private void ExportFile_Click(object sender, RoutedEventArgs e)
private void ExportTheFile();
SaveFileDialog SFD = new SaveFileDialog();
SFD.DefaultExt = "*.txt";
SFD.Filter = "Text (*.txt) | *.txt|All files (*.*)|*.*";
StreamWriter OutStream = new StreamWriter(SFD.OpenFile());