title: How can I dynamically change the converter on DataGridTextColumn binding in WPF?
body: <p>I really don't understand WPF and XAML, and inherited some terribly written code, so I may be butchering this, but here goes.</p>
  
  <p>I inherited a DataGrid bound (in code behind) to a list of Person objects, where the necessary DataGridTextColumns are specified in XAML (presumably to allow styling).</p>
  
  <pre><code>&lt;DataGrid x:Name="PersonGrid" ItemsSource="{Binding}" AutoGenerateColumns="False"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=LastName}" MaxWidth="Infinity" MinWidth="150" Header="Last Name"&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=FirstName}" MaxWidth="Infinity" MinWidth="150" Header="First Name" /&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=DOB, StringFormat=\{0:MM/dd/yyyy\}}" MaxWidth="Infinity" MinWidth="200" Header="Date of Birth (MM/DD/YYYY)" /&gt;
          &lt;DataGridTextColumn Binding="{Binding Path=Number}" MaxWidth="Infinity" MinWidth="150" Header="(P)erson Number" /&gt;
      &lt;/DataGrid.Columns&gt;
      &lt;DataGrid.DataContext&gt;
          &lt;dm:Person /&gt;
      &lt;/DataGrid.DataContext&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>I would like to display just the person's last initial, optionally based on the state of a checkbox.</p>
  
  <pre><code>&lt;CheckBox Name="ShowFullNames_CheckBox" Content="Show Full Names" IsChecked="False"/&gt;
  </code></pre>
  
  <p>I was able to hook up a converter to the LastName Binding in code behind, but get an error ("Binding cannot be changed after it has been used.") when I try to change that converter after the data is bound.</p>
  
  <p>I thought that maybe I could also bind the checkbox IsChecked state to the ConverterParameter or one binding of a Multibinding, but couldn't get that to work.</p>
  
  <pre><code>&lt;DataGridTextColumn MaxWidth="Infinity" MinWidth="150" Header="Last Name"&gt;
      &lt;DataGridTextColumn.Binding&gt;
          &lt;MultiBinding Converter="myStringTruncator"&gt;
              &lt;Binding Source="ShowFullNames_CheckBox" Path="IsChecked"/&gt;
              &lt;Binding Path="LastName"/&gt;
          &lt;/MultiBinding&gt;
      &lt;/DataGridTextColumn.Binding&gt;
  &lt;/DataGridTextColumn&gt;
  </code></pre>
  
  <p>In the Convert method of myStringTruncator, the first binding was just filled with DependencyProperty.UnsetValue, instead of the value of the checkbox.</p>
  
  <p>There's probably a really simple way to do this that I'm not seeing. Any ideas?</p>