Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to specify RowDefinitions and ColumnDefinitions so that it knows how to size the rows and columns. Otherwise it doesn't know whether you want auto-sizing or <a href="https://stackoverflow.com/a/2318082/674077">star-sizing</a>. And it also needs to know how many rows and columns you need up front; it doesn't add them on the fly based on your values of Grid.Row and Grid.Column.</p> <p>I think the code you wrote looks reasonable, and it would be nice if it used a default when you don't specify, but unfortunately it doesn't. Instead, it builds a single-column, single-row grid and stacks all the children on top of each other.</p> <p>I can think of a couple ways to write some XAML that will do what you want.</p> <p>One way:</p> <pre><code>&lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Rectangle Width="100" Height="100" Fill="Red" Grid.Column="0" Grid.Row="0"/&gt; &lt;Rectangle Width="100" Height="100" Fill="Orange" Grid.Column="1" Grid.Row="0"/&gt; ... &lt;/Grid&gt; </code></pre> <p>Another way:</p> <pre><code>&lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;ColumnDefinition Width="100" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="100" /&gt; &lt;RowDefinition Height="100" /&gt; &lt;RowDefinition Height="100" /&gt; &lt;RowDefinition Height="100" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Rectangle Fill="Red" Grid.Column="0" Grid.Row="0"/&gt; &lt;Rectangle Fill="Orange" Grid.Column="1" Grid.Row="0"/&gt; ... &lt;/Grid&gt; </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.
    3. 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