title: Changing Visiblity on a DataGridTemplateColumn works only the first time
body: <p>I was looking at an <a href="https://stackoverflow.com/a/8847705/633267">answer on how to set the visibility of a data grid column</a>, so i added</p>
  
  <pre><code> &lt;UserControl.Resources&gt;
      &lt;BooleanToVisibilityConverter x:Key="b2v" /&gt;
  &lt;/UserControl.Resources&gt;    
  </code></pre>
  
  <p>and then in my xaml I have</p>
  
  <pre><code>&lt;DataGridTemplateColumn Visibility="{Binding Source={x:Reference ShowLookupCheckbox}, 
                                               Path=IsChecked
                                               Converter={StaticResource b2v}}" &gt;
   ...
  &lt;/DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>When my app starts and the checkbox is clear the column is correctly collapsed. When I check the checkbox the column correctly shows. When I click on the checkbox again the column agains is correctly collapsed. <strong>However</strong>, when I click to enable the checkbox a second time I get an <code>InvalidOperationException</code> 
  <em>"Specified element is already the logical child of another element. Disconnect it first."</em></p>
  
  <p>I tried changing the Mode to one way but that didn't help. Anyone know what I'm doing wrong or how to interpret this exception? </p>
  
  <p>I don't think the content of the column matters as it works correctly without the Visibility setting but for the sake of completion here's the full xaml I elided with ... above</p>
  
  <pre><code> &lt;DataGridTemplateColumn.Header&gt;
   &lt;TextBlock  Style="{StaticResource DataGridHeader}"&gt;MO Lookup&lt;/TextBlock&gt;
   &lt;/DataGridTemplateColumn.Header&gt;
  
   &lt;DataGridTemplateColumn.CellTemplate &gt;
    &lt;DataTemplate &gt;
       &lt;Hots:AutoCompleteBoxEx ToolTip="Start typing a Master Order Id"
                               ItemsSource="{Binding AllMoLines,
                                                    UpdateSourceTrigger=PropertyChanged}"
                               Width="50"
                               HorizontalContentAlignment="Left"
                               FilterMode="StartsWith"
                               IsDropDownOpen="True"
                               IsTextCompletionEnabled="True"
                               LostFocus="MoLineBoxLostFocus"
                               SelectedItem="{Binding Path=SelectedMoLine, Mode=TwoWay}" &gt;
  
           &lt;Hots:AutoCompleteBoxEx.ItemTemplate&gt;
               &lt;DataTemplate&gt;
                   &lt;Grid Width="500"&gt;
                       &lt;Grid.ColumnDefinitions&gt;
                           &lt;ColumnDefinition Width="50" /&gt;
                           &lt;ColumnDefinition Width="400" /&gt;
                           &lt;ColumnDefinition Width="50" /&gt;
                       &lt;/Grid.ColumnDefinitions&gt;
                       &lt;TextBlock Text="{Binding HssId, Mode=OneWay}"
                                  Grid.Column="0" /&gt;
                       &lt;TextBlock Text="{Binding Description, Mode=OneWay}"
                                  Grid.Column="1" /&gt;
                       &lt;TextBlock Text="{Binding Unit, Mode=OneWay}"
                                  Grid.Column="2" /&gt;
                   &lt;/Grid&gt;
               &lt;/DataTemplate&gt;
           &lt;/Hots:AutoCompleteBoxEx.ItemTemplate&gt;
       &lt;/Hots:AutoCompleteBoxEx&gt;
  
   &lt;/DataTemplate&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>[EDIT]</strong>
  Here are the first few lines from the Exception stack trace. The whole thing is 66 lines. It's the AddLogicalChild and ChangeLogicalParent that I find perplexing. I'm not sure why checking/unchecking a checkbox linked to a Visibility property is causing a child element to be added</p>
  
  <pre><code>System.InvalidOperationException was unhandled
    Message=Specified element is already the logical child of another element. Disconnect it first.
    Source=PresentationFramework
    StackTrace:
      at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
      at System.Windows.FrameworkElement.AddLogicalChild(Object child)
      at System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)
  </code></pre>