title: InvalidOperationException was unhandled by user code, WPF
body: <p>I have some WPF GUI (hosted in WinForm) which has multiple <code>CheckBoxes</code>. The default value of <code>IsChecked</code> of each <code>CheckBox</code> need come from different boolean fields in some background data. Each boolean field in the background data is mapped to a <code>CheckBox</code> in the <code>VisualTree</code>. So I bind the <code>IsChecked</code> property of each <code>CheckBox</code> to the <code>CheckBox</code> itself and use a Converter to fetch the corresponding boolean value in the background data. This way the <code>CheckBox</code> becomes an input to the Converter function so that the Converter can know its location in the <code>VisualTree</code> and query the correct boolean field in the background data. When the user changes the <code>CheckBox</code>, <code>Checked/Unchecked</code> event-handlers will set the value back to the boolean field in the background data. The XAML is like this:</p>
  
  <pre><code>    &lt;DataTemplate x:Key="ModuleWithEnableControl"&gt;
          &lt;WrapPanel&gt;
              &lt;CheckBox Content="Enable" 
                        IsChecked="{Binding Path=., RelativeSource={RelativeSource Mode=Self}, Mode=OneTime, 
                                    Converter={StaticResource moduleEnableDisableConverter}
                                    }"
                        Checked="ModuleEnabled" Unchecked="ModuleDisabled"
                  /&gt;
          &lt;/WrapPanel&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>The Converter code is like this:</p>
  
  <pre><code>class ModuleEnableDisableConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
        System.Windows.Controls.CheckBox theBox = (System.Windows.Controls.CheckBox)value;
        //Here suppose to get the default value of the CheckBox
        //but just return true for now
        return true;
      }
  }
  </code></pre>
  
  <p>The Checked handler code is like this:</p>
  
  <pre><code>    private void ModuleEnabled(object sender, RoutedEventArgs e)
      {
          MessageBoxResult result = MessageBox.Show("Enabled", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
          if (result == MessageBoxResult.Yes)
          {
            //Check the sender (CheckBox)'s location in the VisualTree,
            //Do set the boolean field in the background data
          }
          return;
      }
  </code></pre>
  
  <p>When program starts, the Converter runs first, since it returns ture, then immediately the Checked handler <code>ModuleEnabled</code> runs. Then the problem happens when executing the <code>MessageBox.Show()</code> in the handler, a <code>Popup</code> window complains:</p>
  
  <blockquote>
    <p>InvalidOperationException was unhandled by user code</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>Dispatcher processing has been suspended</p>
  </blockquote>
  
  <p>but message are still being processed. </p>
  
  <p>If I comment out the <code>MessageBox.Show()</code> line, the program executes as expected. If I don't bind the <code>IsChecked</code> to the <code>CheckBox</code> itself, no problem either, the <code>MessageBox</code> shows perfectly when user changes the <code>CheckBox</code>. I'm wondering why the <code>MessageBox.Show()</code> in the event-handler has conflict with the binding Converter? Also, is there a way to not trigger the Checked handler when setting the initial value using the binding?</p>