Note that there are some explanatory texts on larger screens.

plurals
  1. POMake WPF/SL grid ignore a child element when determining size
    text
    copied!<p>I have a Grid which has several children, one of which is a ScrollViewer. I want the Grid to size itself based on all of its children <em>except</em> the ScrollViewer, which I want to just take up the space that is created by sizing the Grid for the rest of its children. (For example, the Grid is 2x2 and the ScrollViewer is in Row 0, Column 0, and so the other three Grid entries are enough to determine the dimensions of the Grid.)</p> <p>Is there a nice way to do this? I've looked into creating a Custom Panel either to replace the Grid or to contain the ScrollViewer, but at no point during the MeasureOverride/ArrangeOverride calls do I ever get a call which can tell me about the final width/height of the grid row/column I care about (eg, Row 0, Column 0).</p> <p>One thought I had was to derive from Grid and call the base MeasureOverride/ArrangeOverride but remove the ScrollViewer from the Children of the Grid right before the call (and put it back afterwards), but messing with the visual tree during layout computation seems like a bad idea.</p> <p>Here's an example:</p> <pre><code>&lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;Grid VerticalAlignment="Top" HorizontalAlignment="Left"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;ScrollViewer Grid.Row="0" Grid.Column="0" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"&gt; &lt;Button Height="300" Width="300"/&gt; &lt;/ScrollViewer&gt; &lt;Button Grid.Row="1" Grid.Column="0" Height="100" Width="100" Content="1,0"/&gt; &lt;Button Grid.Row="0" Grid.Column="1" Height="100" Width="100" Content="0,1"/&gt; &lt;Button Grid.Row="1" Grid.Column="1" Height="100" Width="100" Content="1,1"/&gt; &lt;/Grid&gt; &lt;/Grid&gt; </code></pre> <p>I would like the size of the Grid to not change as the size of the Button in the ScrollViewer changes - e.g., I want the Grid to give the ScrollViewer the 100x100 square that is determined by the rest of the Grid's contents. And if I changed each of the 3 100x100 buttons to be 200x200, I would want the ScrollViewer to get 200x200, etc.</p> <p>Pavlo's example gets me the closest so far, with the Grid rows/columns appropriately sized, but ScrollViewer does not adapt to the Size given to it when Arrange is called. See below:</p> <p><img src="https://i.stack.imgur.com/Z3Gja.png" alt="Image showing effect of Pavlo&#39;s NoSizeDecorator"></p>
 

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