title: How can I change a wpf Databound grid cell based on the cell value?
body: <p>I'm relatively new to WPF, and am trying to change certain grid cells where the bound values are decimal zeros.  The intent is to leave the cell blank where the cell has 0's.  For example, if the TranDeposit column is zeros, I would like to change that to blanks.  In ASP.NET this is very possible by using the DataBound event.  The XAML code follows:<br /></p>
  
  <pre><code>&lt;DataGrid x:Name="transactionsDataGrid" Grid.Row="3" AutoGenerateColumns="False" EnableRowVirtualization="True"
                      ItemsSource="{Binding}" RowDetailsVisibilityMode="VisibleWhenSelected" RowHeaderWidth="0" Padding="10,0,0,0"
                      AlternatingRowBackground="#FF888888" GridLinesVisibility="Horizontal" SelectionUnit="FullRow" RowBackground="#FFCCCCCC" VerticalAlignment="Top" SelectedIndex="0"
                      HeadersVisibility="Column" Background="#FF292929" Height="355" SelectionChanged="TransactionsDataGrid_SelectionChanged" CanUserAddRows="false" Margin="5,0,5,0"
                             Loaded="DataGrid_RowLoaded"&gt;
  
                          &lt;DataGrid.Columns&gt;
                              &lt;DataGridTextColumn x:Name="tranDateColumn" Binding="{Binding TranDate, StringFormat=MM/dd/yyyy}" Header="Date" Width="90" IsReadOnly="True"/&gt;
                              &lt;DataGridTextColumn x:Name="tranDescriptionColumn" Binding="{Binding TranDescription}" Header="Description" Width="*" IsReadOnly="True"/&gt;
                              &lt;DataGridTextColumn x:Name="tranCategoryColumn" Binding="{Binding TranCategory}" Header="Category" Width="340" IsReadOnly="True"&gt;
                                  &lt;DataGridTextColumn.ElementStyle&gt;
                                      &lt;Style TargetType="TextBlock"&gt;
                                          &lt;!--&lt;Setter Property="HorizontalAlignment" Value="Right" /&gt;--&gt;
                                          &lt;Setter Property="ToolTip" Value="{Binding Path=TranCategory}"/&gt;
                                      &lt;/Style&gt;
                                  &lt;/DataGridTextColumn.ElementStyle&gt;
                              &lt;/DataGridTextColumn&gt;
                              &lt;DataGridTextColumn x:Name="tranNotesColumn" Binding="{Binding TranNotes}" Header="Notes" Width="120" IsReadOnly="True"/&gt;
                              &lt;DataGridCheckBoxColumn x:Name="tranTaxColumn" Binding="{Binding TranTax}" Header="Tax" Width="SizeToHeader" IsReadOnly="True"/&gt;
                              &lt;DataGridCheckBoxColumn x:Name="tranClearedColumn" Binding="{Binding TranCleared}" Header="Cleared" Width="SizeToHeader" IsReadOnly="True" /&gt;
                              &lt;DataGridTextColumn x:Name="tranDepositColumn" Binding="{Binding TranDeposit}" Header="Deposit" Width="80" IsReadOnly="True"/&gt;
                              &lt;DataGridTextColumn x:Name="tranWithdrawlColumn" Binding="{Binding TranWithdrawl}" Header="Withdrawal" Width="80" IsReadOnly="True" /&gt;
                              &lt;DataGridTextColumn x:Name="tranBalanceColumn" Binding="{Binding TranBalance}" Header="Balance" Width="80" IsReadOnly="True"/&gt;
                          &lt;/DataGrid.Columns&gt;
                      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>As you can see I have tried to use the <strong>Loaded</strong> event to access the row, however, there is no row available to dynamically change for this event.  I have tried the <strong>LoadingRow</strong> event, however, when attempting to use the very popular datagrid helper extension "DataGridHelper", I get a NullReferenceException in the GetCell method on the line:</p>
  
  <pre><code>presenter = GetVisualChild&lt;DataGridCellsPresenter&gt;(row);
  </code></pre>
  
  <p>the row value is correct, but the presenter value is null.</p>
  
  <pre><code>public static DataGridCell GetCell(this DataGrid grid, DataGridRow row, int column)
      {
          if (row != null)
          {
              DataGridCellsPresenter presenter = GetVisualChild&lt;DataGridCellsPresenter&gt;(row);
              if (presenter == null)
              {
                  grid.ScrollIntoView(row, grid.Columns[column]);
                  presenter = GetVisualChild&lt;DataGridCellsPresenter&gt;(row);
              }
  
              DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
              return cell;
          }
          return null;
      }
  </code></pre>
  
  <p>Not sure where to go at this point and have searched all over the web for an answer.  I'd really appreciate any help</p>