title: MaterialDesignInXamlToolkit Dialog losing focus
body: <p>I'm using MaterialDesignInXamlToolkit and I have a Dialog that lost focus when I execute some threaded methods.</p>
  
  <ol>
  <li>First, I show a message to the user (works well);</li>
  <li>Then, it starts another dialog with a progress ring (works well);</li>
  <li>At the end, if we have a error response from server, another dialog pops-out with the error message:
  <a href="http://i.stack.imgur.com/A6ymS.jpg" rel="nofollow">No focus</a></li>
  </ol>
  
  <p>The problem is: the "OK" button is disabled. And just receive focus when I click it once.</p>
  
  <p>Here is a source code:
  <a href="https://drive.google.com/open?id=0B7dlCQ9y_LsDdm1mU2RNNzlXem8" rel="nofollow">https://drive.google.com/open?id=0B7dlCQ9y_LsDdm1mU2RNNzlXem8</a></p>
  
  <p>And this is the XAML from MainWindow.xaml:</p>
  
  <pre><code>&lt;Window x:Class="WpfExample.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:WpfExample"
      xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
      mc:Ignorable="d"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;materialDesign:DialogHost Identifier="RootDialog"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Button x:Name="button" Content="Button" Margin="0" Width="88" Height="31" Click="button_Click" Grid.Row="1"/&gt;
  
      &lt;/Grid&gt;
  &lt;/materialDesign:DialogHost&gt;
  </code></pre>
  
  <p></p>
  
  <p>And the MainWindow.xaml.cs:</p>
  
  <pre><code>using MaterialDesignThemes.Wpf;
  using System.Threading.Tasks;
  using System.Windows;
  using WpfExample.Dialogs;
  
  namespace WpfExample
  {
  /// &lt;summary&gt;
  /// Interaction logic for MainWindow.xaml
  /// &lt;/summary&gt;
  public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private void button_Click(object sender, RoutedEventArgs e)
      {
          // Asks for confirmation
          BeforeRemoveItem();
      }
  
      private string RemoveItem()
      {
          /// In my project I'm calling a DELETE on a Rest Server 
          /// and if an error ocurred, we return the error message...
  
          // "Simulates" a delay from server..
          // PS: Without this, the "OK" dialog works fine.
          System.Threading.Thread.Sleep(3000);
  
          // Fake result
          return "An error has ocurred in Server";
  
      }
  
      private async void BeforeRemoveItem()
      {
          var messageDialog = new DialogQuestion
          {
              Message = {Text = "Do you want remove this item?"}
          };
  
          var result = await DialogHost.Show(messageDialog, "RootDialog", OnSelectAnswer);
  
      }
  
      private void OnSelectAnswer(object sender, DialogClosingEventArgs eventArgs)
      {
          if ((bool)eventArgs.Parameter == false)
              return;
  
          // Abort current process...
          eventArgs.Cancel();
  
          // Creates a new dialog, to show the progress bar...
          DialogProgress progresso = new DialogProgress();
          eventArgs.Session.UpdateContent(progresso);
  
          // Then starts a task..
          var t = Task&lt;string&gt;.Run(() =&gt;
          {
              // Calls a methdo from server...
              return RemoveItem();
          })
          .ContinueWith(resultFromServer =&gt;
          {
              // Now, with the answer from server we can do extra things..
  
              // If there is no message, we just close the current Message
              if (resultFromServer.Result == string.Empty)
              {
                  eventArgs.Session.Close(false);
              }
              else
              {
                  // If there is an error message, we show a simple dialog (with just an "OK" button) and shows the error..
                  eventArgs.Cancel();
                  eventArgs.Session.UpdateContent(new DialogOk { Message = { Text = resultFromServer.Result } });
  
              }
          }, TaskScheduler.FromCurrentSynchronizationContext() );
      }
  
     }
  }
  </code></pre>