title: Unable to cast object
body: <p>Why this code does not work</p>
  
  <pre><code>private void dataGrid_LoadingRow(object sender, Microsoft.Windows.Controls.DataGridRowEventArgs e)
      {
          //Highlighting rows
  
          Product product = (Product)e.Row.DataContext;
  
          if (product.Price &gt; 100)
          {
              e.Row.Background = highlightBrush;
          }
          else
          {
              e.Row.Background = normalBrush;
          }
      }
  
  }
  class Product
  {
      public int IdBook ;
      public string NameBook;
      public string Author;
      public string Description;
      public string DateRegister;
      public Int32 Price;
  }
  </code></pre>
  
  <p>xaml:</p>
  
  <pre><code>            &lt;dg:DataGrid Name="dataGrid" AutoGenerateColumns="False"  CanUserAddRows="False" CanUserDeleteRows="False"  IsReadOnly="True"                           
  
  
                      HeadersVisibility="Column" SelectedIndex="-1" Margin="0,315,0,25" Background="#FF484040" BorderBrush="#FF484040" 
  
  SelectionChanged="dataGrid_SelectionChanged" LoadingRow="dataGrid_LoadingRow"&gt;
              &lt;dg:DataGrid.Columns&gt;
                  &lt;dg:DataGridTextColumn Binding="{Binding IdBook}" Header="IdBook" &gt;&lt;/dg:DataGridTextColumn&gt;
                  &lt;dg:DataGridTextColumn Binding="{Binding NameBook}" Header="NameBook"&gt;&lt;/dg:DataGridTextColumn&gt;
                  &lt;dg:DataGridTextColumn Binding="{Binding Author}" Header="Author"&gt;&lt;/dg:DataGridTextColumn&gt;
                  &lt;dg:DataGridTextColumn Binding="{Binding Price}" Header="Price"&gt;&lt;/dg:DataGridTextColumn&gt;
                  &lt;dg:DataGridTextColumn Binding="{Binding DateRegister}" Header="DateRegister"&gt;&lt;/dg:DataGridTextColumn&gt;
                  &lt;dg:DataGridTextColumn Binding="{Binding Description}" Header=Description" Width="*"&gt;&lt;/dg:DataGridTextColumn&gt;
                  &lt;dg:DataGridTemplateColumn&gt;
  
                      &lt;dg:DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;Button Click="Delete_Click"  ToolTip="Delete" Height="30" Width="30" FlowDirection="RightToLeft" Style="{DynamicResource GlassButton}" 
  
  Background="{DynamicResource TileBrush}"&gt;
  
                              &lt;/Button&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/dg:DataGridTemplateColumn.CellTemplate&gt;
  
                  &lt;/dg:DataGridTemplateColumn&gt;
                  &lt;dg:DataGridTemplateColumn Width="15" &gt;
                      &lt;dg:DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;CheckBox ToolTip="Select" Name="Checkbox" Height="15" Width="15" HorizontalContentAlignment="Center" HorizontalAlignment="Center" 
  
  VerticalAlignment="Center" VerticalContentAlignment="Center"&gt;
  
                              &lt;/CheckBox&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/dg:DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/dg:DataGridTemplateColumn&gt;
              &lt;/dg:DataGrid.Columns&gt;
  
  
          &lt;/dg:DataGrid&gt;
  </code></pre>
  
  <p>error :</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Data.DataRowView' to type
    'BooksManagement_Version1.Product'.</p>
  </blockquote>