title: Creating a custom databound tooltip in codebehind
body: <p>How would I create something like this in a code behind?</p>
  
  <pre><code>&lt;Style x:Key="{x:Type ToolTip}" TargetType="ToolTip"&gt;
              &lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt;
              &lt;Setter Property="HasDropShadow" Value="True"/&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="ToolTip"&gt;
                          &lt;Border CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="1" BorderThickness="1,1,1,1"&gt;
                              &lt;Border.Background&gt;
                                  &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt;
                                      &lt;GradientStop Color="#F7D073" Offset="0"/&gt;
                                      &lt;GradientStop Color="#F1A62F" Offset="1"/&gt;
                                  &lt;/LinearGradientBrush&gt;
                              &lt;/Border.Background&gt;
                              &lt;Grid&gt;
                                  &lt;Grid.ColumnDefinitions&gt;
                                      &lt;ColumnDefinition Width="Auto"/&gt;
                                      &lt;ColumnDefinition Width="*"/&gt;
                                  &lt;/Grid.ColumnDefinitions&gt;
                                  &lt;Grid.RowDefinitions&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                  &lt;/Grid.RowDefinitions&gt;
                                  &lt;Border HorizontalAlignment="Stretch" BorderThickness="0,0,0,1" BorderBrush="Black" Margin="5" Grid.ColumnSpan="2"&gt;
                                      &lt;TextBlock FontSize="14" TextAlignment="Left" Text="{TemplateBinding Content}"/&gt;
                                  &lt;/Border&gt;
                                  &lt;TextBlock Grid.Column="0" Grid.Row="1" Margin="10,0,5,0"&gt;Column1:&lt;/TextBlock&gt;
                                  &lt;TextBlock Grid.Column="1" Grid.Row="1" FontWeight="Bold" Text="{Binding Column1}"  TextAlignment="Left" /&gt;
                                  &lt;TextBlock Grid.Column="0" Grid.Row="2" Margin="10,0,5,0"&gt;Column2:&lt;/TextBlock&gt;
                                  &lt;TextBlock Grid.Column="1" Grid.Row="2" FontWeight="Bold" Text="{Binding Column2}" TextAlignment="Left" /&gt;
                                  &lt;TextBlock Grid.Column="0" Grid.Row="3" Margin="10,0,5,0"&gt;Column3:&lt;/TextBlock&gt;
                                  &lt;TextBlock Grid.Column="1" Grid.Row="3" FontWeight="Bold" Text="{Binding Column3}" TextAlignment="Left" /&gt;
                                  &lt;TextBlock Grid.Column="0" Grid.Row="4" Margin="10,0,5,0"&gt;Column4:&lt;/TextBlock&gt;
                                  &lt;TextBlock Grid.Column="1" Grid.Row="4" FontWeight="Bold" Text="{Binding Column4}" TextAlignment="Left" /&gt;
                                  &lt;TextBlock Grid.Column="0" Grid.Row="5" Margin="10,0,5,0"&gt;Column5:&lt;/TextBlock&gt;
                                  &lt;TextBlock Grid.Column="1" Grid.Row="5" FontWeight="Bold" Text="{Binding Column5}" TextAlignment="Left" /&gt;
                                  &lt;TextBlock Grid.Column="0" Grid.Row="6" Margin="10,0,5,0"&gt;ColumnX:&lt;/TextBlock&gt;
                                  &lt;TextBlock Grid.Column="1" Grid.Row="6" FontWeight="Bold" Text="{Binding ColumnX}" TextAlignment="Left" /&gt;
                              &lt;/Grid&gt;
                          &lt;/Border&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
  </code></pre>
  
  <p>The idea is to pass in a DataTable to the control with an unknown number of columns and be able to build a tooltip with however many columns there are.</p>
  
  <p>The above code was used to build a very specific case but now I would like to make this as generic as possible however my knowledge of WPF codebehind is not where it needs to be to creat something like this. </p>