title: Launch hyperlink event handler on datagrid cell click
body: <p>I have an WPF datagrid which has some columns. One of them is a DataGridHyperlinkColumn.</p>
  
  <p>Datagrid's SelectedItem event is attached to a property of my view model. This property is called MySelectedItem.</p>
  
  <p>When any of the row's cells is selected property setter is fired. Setter launches a background worker to do some stuff.</p>
  
  <p>Also this property is updated from view model so the changes are propagated to the view.</p>
  
  <p>The problem that I have is with the DataGridHyperlinkColumn. I have attached an event handler to the hyperlink that popups a custom wpf window with a message. The problem comes here: When I click on the hyperlink and the row is not previously selected, the datagrid selecteditem event is fired, not the event handler attached to the hyperlink. The event handler attached to the hyperlink is only fired if the row has been previously selected.</p>
  
  <p>The behavior I would like is: </p>
  
  <ul>
  <li>If I click on the cell hyperlink the background worker should not be
  started, I mean, event attached to datagrid selectedItem event should
  not be fired. In this case only hyperlink event handler should be fired. Also datagrid row should not be marked as selected.</li>
  <li>Otherwise, If I click on a datagrid cell different from the hyperlink, the
  datagrid selectedItem event should be fired (this last case is
  working without problems).</li>
  </ul>
  
  <p><strong>View</strong>:</p>
  
  <pre><code>&lt;Window x:Class="DataGridExample.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" 
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;my:DataGrid x:Name="MyDataGrid" 
                SelectedItem="{Binding Path=MySelectedItem}"
                ItemsSource="{Binding Path=MyListOfItems}"               
                AutoGenerateColumns="False"&gt;
          &lt;my:DataGrid.Columns&gt;
             &lt;my:DataGridHyperlinkColumn Header="LinkColumn" 
                 Binding="{Binding myExtraData.LinkName}" 
                 ContentBinding="{Binding myExtraData.LinkValue}"&gt;
                 &lt;my:DataGridHyperlinkColumn.ElementStyle&gt;
                   &lt;Style TargetType="TextBlock"&gt;
                      &lt;EventSetter Event="Hyperlink.Click" Handler="OnCellHyperlinkClick" /&gt;
                   &lt;/Style&gt;
                 &lt;/my:DataGridHyperlinkColumn.ElementStyle&gt;
             &lt;/my:DataGridHyperlinkColumn&gt;
          &lt;/my:DataGrid.Columns&gt;
      &lt;/my:DataGrid&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Model</strong>:
  MySelectedItem property is set within some points in the view model below.
  I do not show here to simplify.</p>
  
  <pre><code>public class MyViewModel  : ViewModelBase
  {
      public MyItems MySelectedItem
      {
          get { return mySelectedItem; }
  
          set
          {                    
                  mySelectedItem= value;
  
                  InitiateBgWorker();
  
                  OnPropertyChanged("MySelectedItem");
              }
          }
      }
  
      // Other properties, methods, etc.
  }
  </code></pre>