title: WPF How do I return value to the main program from Button Click
body: <p>I am new to WPF and C# and cannot understand how to return a value from inside a <code>Button_Click</code>.</p>
  
  <p>I am trying to get the user to select a file location then pass that location to the main program. Here is my code so far which works but I cannot pass the string back.</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }   
  
      public static string Button_Click(object sender, RoutedEventArgs e)
      {
          var dialog = new System.Windows.Forms.FolderBrowserDialog();
          System.Windows.Forms.DialogResult result = dialog.ShowDialog();
          string FolderLocation  = dialog.SelectedPath; //this is c:/folder
  
          return FolderLocation;
      }
  
      // need to use FolderLocation here to do some stuff.
  }
  </code></pre>