Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I arrived on this by trial and error, so long ass you are using an ItemsSource data source it should work fine. It should work with virtual rows and causes only a brief visual pause and it switches over (this seems mainly down to column autogeneration so can be avoided). </p> <p>As hacks go it has the advantage of simplicity and the use of mechanics which are not expected to change. </p> <p>The heuristic on user triggering of the action might be improved but it has not failed on me yet.</p> <pre><code>using Microsoft.Windows.Controls; using Microsoft.Windows.Controls.Primitives; public static class DataGridExtensions { public static void LinkRowHeightsToUserChange(this DataGrid dataGrid) { double? heightToApply = null; bool userTriggered = false; if (dataGrid.RowHeaderStyle == null) dataGrid.RowHeaderStyle = new Style(typeof(DataGridRowHeader)); if (dataGrid.RowStyle == null) dataGrid.RowStyle = new Style(typeof(DataGridRow)); dataGrid.RowStyle.Setters.Add(new EventSetter() { Event = DataGridRow.SizeChangedEvent, Handler = new SizeChangedEventHandler((r, sizeArgs) =&gt; { if (userTriggered &amp;&amp; sizeArgs.HeightChanged) heightToApply = sizeArgs.NewSize.Height; }) }); dataGrid.RowHeaderStyle.Setters.Add(new EventSetter() { Event = DataGridRowHeader.PreviewMouseDownEvent, Handler = new MouseButtonEventHandler( (rh,e) =&gt; userTriggered = true) }); dataGrid.RowHeaderStyle.Setters.Add(new EventSetter() { Event = DataGridRowHeader.MouseLeaveEvent, Handler = new MouseEventHandler((o, mouseArgs) =&gt; { if (heightToApply.HasValue) { userTriggered = false; var itemsSource = dataGrid.ItemsSource; dataGrid.ItemsSource = null; dataGrid.RowHeight = heightToApply.Value; dataGrid.ItemsSource = itemsSource; heightToApply = null; } }) }); } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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