Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Or you could use this grid I just made. It will automatically add a border to every cell in the grid. This is the result:</p> <p><img src="https://i.stack.imgur.com/pZv5O.png" alt="enter image description here"></p> <p>C#:</p> <pre><code>using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace GridWithBorder { public class BorderGrid : Grid { protected override void OnRender(DrawingContext dc) { double leftOffset = 0; double topOffset = 0; Pen pen = new Pen(Brushes.Black, 3); pen.Freeze(); foreach (RowDefinition row in this.RowDefinitions) { dc.DrawLine(pen, new Point(0, topOffset), new Point(this.ActualWidth, topOffset)); topOffset += row.ActualHeight; } // draw last line at the bottom dc.DrawLine(pen, new Point(0, topOffset), new Point(this.ActualWidth, topOffset)); //foreach (ColumnDefinition column in this.ColumnDefinitions) //{ // dc.DrawLine(pen, new Point(leftOffset, 0), new Point(leftOffset, this.ActualHeight)); // leftOffset += column.ActualWidth; //} // draw last line on the right //dc.DrawLine(pen, new Point(leftOffset, 0), new Point(leftOffset, this.ActualHeight)); base.OnRender(dc); } } } </code></pre> <p>XAML:</p> <pre><code>&lt;Window x:Class="GridWithBorder.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:GridWithBorder" Title="MainWindow" Height="350" Width="525"&gt; &lt;local:BorderGrid&gt; &lt;local:BorderGrid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition /&gt; &lt;RowDefinition /&gt; &lt;/local:BorderGrid.RowDefinitions&gt; &lt;local:BorderGrid.ColumnDefinitions&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition /&gt; &lt;/local:BorderGrid.ColumnDefinitions&gt; &lt;Rectangle Grid.Row="0" Grid.Column="0" Fill="Red" Margin="5" /&gt; &lt;Rectangle Grid.Row="0" Grid.Column="1" Fill="Blue" Margin="5" /&gt; &lt;Rectangle Grid.Row="0" Grid.Column="2" Fill="Orange" Margin="5" /&gt; &lt;Rectangle Grid.Row="0" Grid.Column="3" Fill="Red" Margin="5" /&gt; &lt;Rectangle Grid.Row="1" Grid.Column="0" Fill="Yellow" Margin="5" /&gt; &lt;Rectangle Grid.Row="1" Grid.Column="1" Fill="Green" Margin="5" /&gt; &lt;Rectangle Grid.Row="1" Grid.Column="2" Fill="Purple" Margin="5" /&gt; &lt;Rectangle Grid.Row="1" Grid.Column="3" Fill="Green" Margin="5" /&gt; &lt;Rectangle Grid.Row="2" Grid.Column="0" Fill="Orange" Margin="5" /&gt; &lt;Rectangle Grid.Row="2" Grid.Column="1" Fill="Red" Margin="5" /&gt; &lt;Rectangle Grid.Row="2" Grid.Column="2" Fill="Blue" Margin="5" /&gt; &lt;Rectangle Grid.Row="2" Grid.Column="3" Fill="Red" Margin="5" /&gt; &lt;/local:BorderGrid&gt; &lt;/Window&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. 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