title: silverlight 4 image preview from tooltip on datagrid
body: <p>I currently have a datagrid that goes and gets results from my database based on a server file structure.  So, we create PDFs and PPTs, load them into the directory, and add them to that database accordingly.  Then a user can search for what they need and the results get displayed in my datagrid.  There are two columns that have image hyperlink buttons relating to each PDF and PPT for that particular piece.</p>
  
  <p>Then, when a user clicks the PDF icon or PPT icon, it brings up the high-res piece in another window.  No problems there, but now I want it so that when a user hovers over the icon, it brings up a preview of the high res piece inside the tooptip.  I can hard code images into the tooltip no problem.  So in that aspect we created little thumbnail preview images of each PDF/PPT.  They are all sized correctly and ready to go, I just need to bind the location to the tooltip so that it basically shows a 'thumbnail' preview for each high-res document.</p>
  
  <p>Here is my XAML:</p>
  
  <pre><code>&lt;sdk:DataGridTemplateColumn x:Name="imageColPdf" Header="PDF" Width="SizeToHeader" IsReadOnly="False"&gt;
     &lt;sdk:DataGridTemplateColumn.CellTemplate&gt;
             &lt;DataTemplate&gt;
                 &lt;HyperlinkButton HorizontalAlignment="Center" VerticalAlignment="Center" DataContext="{Binding Path=FileName}" Click="HyperlinkButtonPDF_Click" &gt;
                       &lt;Image Source="/PrintOnDemand;component/Images/16x16/page_white_acrobat.png" Stretch="None"  HorizontalAlignment="Center" &gt;&lt;/Image&gt;
                            &lt;ToolTipService.ToolTip&gt;
                                &lt;ToolTip&gt;
                                     &lt;ToolTip.Content&gt;
                                         &lt;Image DataContext="{Binding Path=FileName}" Name="LoadPDFImage" Loaded="PDFImageToolTip"/&gt;
                                     &lt;/ToolTip.Content&gt;
                                 &lt;/ToolTip&gt;
                             &lt;/ToolTipService.ToolTip&gt;
                         &lt;/HyperlinkButton&gt;
                     &lt;/DataTemplate&gt;
                 &lt;/sdk:DataGridTemplateColumn.CellTemplate&gt;
             &lt;/sdk:DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>Then here is the code-behind for the tooltip loaded image event:</p>
  
  <pre><code>private void PDFImageToolTip(object sender, RoutedEventArgs e)
      {
  
          string docname = ((System.Windows.FrameworkElement)((e.OriginalSource as Image).DataContext)).ToString();
          string baseUri = "http://localhost:51840/ShowDocument.aspx?DocumentName=" + docname + "&amp;type=pdfjpg";
          var hostingWindow = HtmlPage.Window;
          hostingWindow.Navigate(new Uri(baseUri, UriKind.Absolute), "_blank");
      }
  </code></pre>
  
  <p>I did this method on the click event to call the high res documents, but when i try to load the images through the tooltip, I am getting an error every time I debug (System.NullReferenceException) and object reference not set to an instance of an object.
  It seems to not be able to get the correct filename/source path of the image. It fails every time on the string docname.  Ok so, my question is, how can I get it to properly go through and display the image we already have set up. </p>