Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF - How to stop an ItemsControl pseudo-grid's columns from dancing/jumping around during layout
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/957771/displaying-a-data-bound-stackpanel-inside-a-datatemplate">Several</a> <a href="https://stackoverflow.com/questions/1036831/synchronizing-wpf-control-widths-in-a-wrappanel">other</a> <a href="https://stackoverflow.com/questions/539174/wpf-grid-column-maxwidth-not-enforced">questions</a> <a href="https://stackoverflow.com/questions/1032035/showing-a-dynamic-size-list-in-xaml-readonly">on</a> <a href="https://stackoverflow.com/questions/691339/wpf-gridviewrowpresenter-in-an-itemscontrol">SO</a> have come to the same conclusion I have -- using an <code>ItemsControl</code> with a <code>DataTemplate</code> for each item constructed to position items such that they resemble a grid is much simpler (especially to format) than using a <code>ListView</code>.</p> <p>The code resembles:</p> <pre><code>&lt;StackPanel Grid.IsSharedSizeScope="True"&gt; &lt;!-- Header --&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Column1" /&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Column2" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Grid.Column="0" Text="Column Header 1" /&gt; &lt;TextBlock Grid.Column="1" Text="Column Header 2" /&gt; &lt;/Grid&gt; &lt;!-- Items --&gt; &lt;ItemsControl ItemsSource="{Binding Path=Values, Mode=OneWay}"&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Column1" /&gt; &lt;ColumnDefinition Width="Auto" SharedSizeGroup="Column2" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Grid.Column="0" Text="{Binding ColumnProperty1}" /&gt; &lt;TextBlock Grid.Column="1" Text="{Binding ColumnProperty2}" /&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/StackPanel&gt; </code></pre> <p>The problem I'm seeing is that whenever I swap the object to which the <code>ItemsSource</code> is bound (it's an <code>ObservableCollection</code> that I replace the reference to, rather than clear and re-add), the entire 'grid' dances about for a few seconds.</p> <p>Presumably it is making a few layout passes to get all the <code>Auto</code>-width columns to match up.</p> <p>This is very distracting for my users and I'd like to get it sorted out. Has anyone else seen this?</p>
    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.
 

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