---
title: "Column marging on a WPF Grid"  
description: "Column marging on a WPF Grid"  
author: "Anonymous User"  
published: 2013-10-14  
updated: 2013-10-14  
canonical: https://www.mindstick.com/forum/1674/column-marging-on-a-wpf-grid  
category: "wpf"  
tags: ["wpf"]  
reading_time: 3 minutes  

---

# Column marging on a WPF Grid

I created a [grid](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid). On this grid, i have two colums with two TextBlock I would like to [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) a [space](https://www.mindstick.com/articles/12954/do-your-electrical-repair-in-your-own-space) between my columns, in [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) to having space between my textBlocks.

How doing this ?

**Here is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) :**

```
    <ListBox x:Name="ListBoxTiers" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                                <Grid Margin="10" VerticalAlignment="Top" HorizontalAlignment="Stretch">
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>

                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Grid.Row="0" Grid.Column="0" x:Name="TxtBox_CodeTiers" TextWrapping="Wrap" Text="{Binding m_strCode}"  HorizontalAlignment="Stretch" VerticalAlignment="Top" />
                                    <TextBlock Grid.Row="0" Grid.Column="1" x:Name="TxtBox_NomTiers" TextWrapping="Wrap" Text="{Binding m_strNom}"   HorizontalAlignment="Stretch" VerticalAlignment="Top" />
                                </Grid>
                            </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
```

## Replies

### Reply by Aaron Douglas

Instead of playing with the columnns, set a margin around the textbox.

```
<TextBox Margin="10">
```

You can set each side independently or set left/right and up/down:

```
<TextBox Margin="10, 3, 7, 0">
<TextBox Margin="10, 5">
```

Or wrap your TextBoxes inside another panel and set the margin there:

```
<Grid Margin="10">
    <TextBox />
    <TextBox />
</Grid>
```


---

Original Source: https://www.mindstick.com/forum/1674/column-marging-on-a-wpf-grid

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
