Note that there are some explanatory texts on larger screens.

plurals
  1. POResizable WPF Grid inserts blank lines between rows and columns depending on actual size
    primarykey
    data
    text
    <p>I have a <code>Grid</code> displaying rectangles. The <code>Grid</code> can be resized and is supposed to display adjacent rectangles without any gap.</p> <p>However, depending on the actual size of the <code>Grid</code>, blank lines appear between the rows and columns of the <code>Grid</code>. I guess this is to make up for sizes where the width isn't a multiple of the number of columns, or the height isn't a multiple of the number of rows.</p> <p>The following XAML code demonstrates this:</p> <pre><code>&lt;Window x:Class="test.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;ColumnDefinition&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;RowDefinition&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;Rectangle Grid.Column="0" Grid.Row="0" Fill="DarkBlue"&gt;&lt;/Rectangle&gt; &lt;Rectangle Grid.Column="1" Grid.Row="0" Fill="DarkOrange"&gt;&lt;/Rectangle&gt; &lt;Rectangle Grid.Column="0" Grid.Row="1" Fill="DarkBlue"&gt;&lt;/Rectangle&gt; &lt;Rectangle Grid.Column="1" Grid.Row="1" Fill="DarkBlue"&gt;&lt;/Rectangle&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>How can I prevent those blank lines? If one or some of the columns/rows are slightly larger than others is not really a problem. I'd like to keep the markup simple.</p> <p>I unsuccessfully tried <code>Stretch</code>, <code>Fill</code>, putting the <code>Grid</code> in a <code>ViewBox</code>, <code>ShowGridLines=False, Width=Auto</code>, etc.</p> <p>An image of the issue is as follows:</p> <p><img src="https://i.stack.imgur.com/qXkdt.png" alt="enter image description here"></p>
    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. 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