title: DataGridTemplateColumn - exception when DoubleClick
body: <p>I'm getting exception:</p>
  
  <blockquote>
    <p>'{0}' is not a Visual or Visual3D.</p>
  </blockquote>
  
  <p>The only question I found that similar: <a href="https://stackoverflow.com/questions/2375237/wpf-system-argumentexception-0-is-not-a-visual-or-visual3d/2414886#2414886">WPF: System.ArgumentException =&gt; {&quot;&#39;{0}&#39; is not a Visual or Visual3D.&quot;}</a></p>
  
  <p>I'm just building "pretty" grid. No need to handle double-clicks. It's just side-effect when user double-clicks by mistake - this exception throws.</p>
  
  <p>XAML looks like this:</p>
  
  <pre><code>&lt;DataGrid
    ItemsSource="{Binding Source={StaticResource TrucksSource}}"
    CanUserReorderColumns="False" 
    CanUserResizeColumns="True" 
    CanUserResizeRows="False" 
    AutoGenerateColumns="False" 
    BorderThickness="0" 
    CanUserAddRows="False" 
    RowBackground="{StaticResource GrayBackgroundGradientBrush}"
    RowHeight="20" Focusable="False" RowHeaderWidth="0"&gt;
    &lt;DataGrid.Columns&gt;
        &lt;DataGridTemplateColumn Header="Select" Width="40" CanUserSort="True" SortMemberPath="IsSelected"&gt;
            &lt;DataGridTemplateColumn.CellTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;CheckBox
                        IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center" /&gt;
                &lt;/DataTemplate&gt;
            &lt;/DataGridTemplateColumn.CellTemplate&gt;
        &lt;/DataGridTemplateColumn&gt;
        &lt;DataGridTemplateColumn Header="Team" Width="42" CanUserSort="True" SortMemberPath="TeamDispatcherCaptionShort"&gt;
            &lt;DataGridTemplateColumn.CellTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;Border
                    Margin="-2,-1"&gt;
                        &lt;TextBlock ToolTip="{Binding TeamDispatcherCaptionLong}" 
                        Foreground="#414141" FontFamily="Arial" FontSize="12"
                        Text="{Binding TeamDispatcherCaptionShort}" 
                        HorizontalAlignment="Center" VerticalAlignment="Center" /&gt;
                    &lt;/Border&gt;
                &lt;/DataTemplate&gt;
            &lt;/DataGridTemplateColumn.CellTemplate&gt;
        &lt;/DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>I get exception whenever user double-clicks. First column is checkbox. When it's single-click-ed it works correct. When I click in any area around checkbox - exception.</p>
  
  <p>How do I fix it? There is no code behind, it's MVVM project</p>
  
  <p>EDIT:</p>
  
  <p>Ok, I went ahead and tried to repro this on small project. I already figured issue but want to know your take on this.. And I need to award this bounty :)</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;CollectionViewSource x:Key="WidgetsSource" Source="{Binding Widgets}" /&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;DataGrid
              ItemsSource="{Binding Source={StaticResource WidgetsSource}}"
              CanUserReorderColumns="False" 
              CanUserResizeColumns="True" 
              CanUserResizeRows="False" 
              AutoGenerateColumns="False" 
              BorderThickness="0" 
              CanUserAddRows="False" 
              VerticalGridLinesBrush="#00000000" 
              HorizontalGridLinesBrush="Gray" 
              RowBackground="LightGray"
              RowHeight="20" Focusable="False" RowHeaderWidth="0" SelectionUnit="Cell"&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTemplateColumn Header="Prop1" Width="50" CanUserSort="True" SortMemberPath="Prop1"&gt;
                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;Border&gt;
                                  &lt;TextBlock&gt;
                                      &lt;Run Text="{Binding NestWidg.Prop1}" /&gt;
                                  &lt;/TextBlock&gt;
                              &lt;/Border&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/DataGridTemplateColumn&gt;
                  &lt;DataGridTemplateColumn Header="Prop2" Width="50" CanUserSort="True" SortMemberPath="Prop1"&gt;
                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;Border&gt;
                                  &lt;TextBlock Text="{Binding Prop1}" /&gt;
                              &lt;/Border&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/DataGridTemplateColumn&gt;                
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>VM:</p>
  
  <pre><code>namespace WpfApplication1
  {
      using System.Collections.ObjectModel;
  
      public class MainWindowVM
      {
          public ObservableCollection&lt;Widget&gt; Widgets { get; set; }
  
          public MainWindowVM()
          {
              this.Widgets = new ObservableCollection&lt;Widget&gt;();
  
              this.Widgets.Clear();
              this.Widgets.Add(new Widget("a", "b") { NestWidg = new NestWidget { Prop1 = "Nest" } });
          }
      }
  
      public class Widget
      {
          public Widget(string p1, string p2)
          {
              Prop1 = p1;
              Prop2 = p2;
          }
  
          public string Prop1 { get; private set; }
  
          public string Prop2 { get; private set; }
  
          public NestWidget NestWidg { get; set; }
      }
  
      public class NestWidget
      {
          public string Prop1 { get; set; }
      }
  }
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code>namespace WpfApplication1
  {
      using System.Windows;
  
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              this.InitializeComponent();
              this.DataContext = new MainWindowVM();
          }
      }
  }
  </code></pre>