Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is also following way which you can use to dynamically format DataGridCell whenever its value changes by using Binding.TargetUpdated or Binding.SourceUpdated event on DataGridCell.</p> <p>To do this, you must do following:</p> <ul> <li>Add event handler for AutoGeneratingColumn event on DataGrid. For example: </li> </ul> <p><code>&lt;DataGrid ItemsSource="{Binding}" AutoGeneratingColumn="OnAutoGeneratingColumn"/&gt;</code></p> <ul> <li><p>In AutoGeneratingColumn handler identify if auto-generated column has Binding and if so, set NotifyOnTargetUpdated on it to true and set CellStyle on column which will include EventSetter for Binding.TargetUpdatedEvent event. For example:</p> <pre><code>void OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { BindingBase bindingBase = null; var dataGridBoundColumn = e.Column as DataGridBoundColumn; if (dataGridBoundColumn != null) { bindingBase = dataGridBoundColumn.Binding; } else { var dataGridComboBoxColumn = e.Column as DataGridComboBoxColumn; if (dataGridComboBoxColumn != null) bindingBase = dataGridComboBoxColumn.SelectedItemBinding; } var binding = bindingBase as Binding; if (binding != null) { binding.NotifyOnTargetUpdated = true; e.Column.CellStyle = new Style(typeof(DataGridCell)) { Setters = { new EventSetter(Binding.TargetUpdatedEvent, new EventHandler&lt;DataTransferEventArgs&gt;(OnDataGridCellBindingTargetUpdated)) } }; } } </code></pre></li> <li><p>Implement your custom logic for formatting DataGridCell when value changes in OnDataGridCellBindingTargetUpdated handler. For example:</p> <pre><code>private static void OnDataGridCellBindingTargetUpdated(object sender, DataTransferEventArgs e) { var dataGridCell = (DataGridCell)sender; // Get context: column and item. var column = dataGridCell.Column; var item = dataGridCell.DataContext; // TODO: based on context, format DataGridCell instance. } </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload