title: How to bind a Tooltip's content to an MVVM property within code?
body: <p>Due the nature of our software, we have to create our datagrid columns dynamically in code behind and add it then to the datagrid like this:</p>
  
  <pre><code>DataGridBoundColumn dataGridBoundColumn = new DataGridTextColumn
                                                            {
                                                                CellStyle = ...,                                                                            
                                                                Header = header,
                                                                Binding = binding
                                                            };
  reportDataGrid.Columns.Add(dataGridBoundColumn);
  </code></pre>
  
  <p>Now we need a tooltip on the columnheader:</p>
  
  <pre><code>ToolTipService.SetToolTip(dataGridBoundColumn, "ENTER VALUE");
  </code></pre>
  
  <p>Well that works fine too. However I need to bind the tooltip's value to a property on the ViewModel.  I know how to do this in the xaml, but no idea how to do that in code.</p>
  
  <p>Any help would be appreciated,</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks to Steve's answer I was able to fix this slightly differently:</p>
  
  <pre><code>Binding bindingBoundToTooltipProperty = new Binding()
                                     {
                                         Source = reportDataGrid.DataContext, 
                                         Path = new PropertyPath("ToolTipSorting")
                                     };
  
  
  BindingOperations.SetBinding(dataGridBoundColumn, ToolTipService.ToolTipProperty, bindingBoundToTooltipProperty);
  </code></pre>
  
  <p>if the DataGridColumnHeaderStyle was customized, make sure to add these lines to the template as well:</p>
  
  <pre><code>&lt;Trigger Property="IsMouseOver" Value="True"&gt;
      &lt;Setter Property="ToolTip" Value="{Binding Column.(ToolTipService.ToolTip), RelativeSource={RelativeSource Self}}"/&gt;
  &lt;/Trigger&gt;
  </code></pre>