title: Why does WPF application not react correctly on DialogResult value if System.Windows.Forms.FolderBrowserDialog is used in this WPF application?
body: <p>I use <code>System.Windows.Forms.FolderBrowserDialog</code> instance in my WPF MVVM application. Please see the following code from the View Model:</p>
  
  <pre><code>. . . . . . . .
  using System.Windows.Forms;
  . . . . . . . .
  FolderBrowserDialog dialog = new FolderBrowserDialog();
  DialogResult res = dialog.ShowDialog();
  if (res == DialogResult.OK)
  {
     this.PathToExcelExportRepository = string.Copy(dialog.SelectedPath);
     this.IsTurnOffExportToExcelSelected = false;
     this.IsTurnOnExportToExcelSelected = true;
     . . . . . . . . .
  }
  </code></pre>
  
  <p>Where <code>IsTurnOffExportToExcelSelected</code> is:</p>
  
  <pre><code>   public bool IsTurnOffExportToExcelSelected
     {
          get { return this._isTurnOffExportToExcelSelected; }
          set { this.SetProperty(ref this._isTurnOffExportToExcelSelected, value); }
     }
  </code></pre>
  
  <p>and <code>IsTurnOnExportToExcelSelected</code> is:</p>
  
  <pre><code>public bool IsTurnOnExportToExcelSelected
  {
     get { return this._isTurnOnExportToExcelSelected; }
     set { this.SetProperty(ref this._isTurnOnExportToExcelSelected, value); }
  }
  </code></pre>
  
  <p>Each one of these properties is binding source fore menu item in the View:</p>
  
  <pre><code>&lt;telerik:RadContextMenu.ContextMenu&gt;
     &lt;telerik:RadContextMenu&gt;
         &lt;telerik:RadMenuItem Header="Turn on export to MS Excel" IsCheckable="True" IsChecked="{Binding IsTurnOnExportToExcelSelected, Mode=TwoWay}"
                                   Command="{Binding TurnOnExportToExcelCommand}"/&gt;
         &lt;telerik:RadMenuItem Header="Turn off export to MS Excel" IsCheckable="True" IsChecked="{Binding IsTurnOffExportToExcelSelected, Mode=TwoWay}"
                                   Command="{Binding TurnOffExportToExcelCommand}"/&gt;
     &lt;/telerik:RadContextMenu&gt;
  &lt;/telerik:RadContextMenu.ContextMenu&gt;
  </code></pre>
  
  <p>The condition of if-statement above is satisfied if <code>DialogResult</code> is <code>DialogResult.OK</code>. I verify it to set breakpoint in debugger. But if I click 'Cancel' button in the dialog then the debugger doesn't not show next steps but <code>IsChecked</code> property of <code>IsTurnOnExportToExcelSelected</code> menu item is set to <code>true</code> (the status of <code>IsChecked</code> property of <code>TurnOffExportToMSExcel</code> menu item is not changed). Why is <code>TurnOnExportToMSExcel</code> boolean property set to true if <code>DialogResult</code> is <code>Cancel</code>?</p>
  
  <p><em>As <strong>wkl</strong> suggested I show here the source code of <code>TurnOnExportToExcelCommand</code>. It turns on export to CSV-file of the values of real-time chart data-points:</em></p>
  
  <pre><code>// This line is in the View Model constructor.
  this.TurnOnExportToExcelCommand = new DelegateCommand(this.turnOnExportToExcel);
  
  // This is the command definition in the View Model.
  public DelegateCommand TurnOnExportToExcelCommand { get; private set; }
  
      private void turnOnExportToExcel()
      {
          FolderBrowserDialog dialog = new FolderBrowserDialog();
          DialogResult res = dialog.ShowDialog();
  
          if (res == DialogResult.OK)
          {
              this.PathToExcelExportRepository = string.Copy(dialog.SelectedPath);
  
              this.IsTurnOffExportToExcelSelected = false;
              this.IsTurnOnExportToExcelSelected = true;
              // Define for which chart (absolute or relative) export to CSV-file is turned on.
              if (this.IsAbsoluteSplineChartSelected || this.IsAbsoluteBarChartSelected)
              {
                  // Export of absolute chart data-point to CSV-file:
                  Interlocked.CompareExchange(ref this._isAbsoluteChartDataBeingExported, 1, 0);
                  Task.Factory.StartNew(this.peekAbsoluteDataForExportToCsv, TaskCreationOptions.LongRunning);
                  Task.Factory.StartNew(this.exportToCsvAbsoluteChartPoints, TaskCreationOptions.LongRunning);
                  // Export absolute chart data-point values is turned on.
                  GlobalStaticMembers.ChartsExportToExcelStatus[0] = true;
              }
              else if (this.IsComparativeSplineChartSelected || this.IsComparativeBarChartSelected)
              {
                  // Export of relative chart data-point to CSV-file:
                  Interlocked.CompareExchange(ref this._isComparativeChartDataBeingExported, 1, 0);
                  Task.Factory.StartNew(this.peekComparativeDataForExportToCsv, TaskCreationOptions.LongRunning);
                  Task.Factory.StartNew(this.exportToCsvComparativeChartPoints, TaskCreationOptions.LongRunning);
                  // Export relative chart data-point values is turned on.
                  GlobalStaticMembers.ChartsExportToExcelStatus[1] = true;
              }
          }
      }
  </code></pre>
  
  <p>If you need, then I'll give you source code of method that are called from this command: peekAbsoluteDataForExportToCsv, exportToCsvAbsoluteChartPoints, peekComparativeDataForExportToCsv, exportToCsvComparativeChartPoints.</p>