Home > DeveloperSection > Forums > Column marging on a WPF Grid
C G E Mannerheim
C G E Mannerheim

Total Post:29

Posted on    October-14-2013 7:33 AM


 1 Reply(s)
 1135  View(s)
Rate this:

I created a grid. On this grid, i have two colums with two TextBlock I would like to insert a space between my columns, in order to having space between my textBlocks.

How doing this ?

Here is my code :

            <ListBox x:Name="ListBoxTiers" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0"> 
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                                <Grid Margin="10" VerticalAlignment="Top" HorizontalAlignment="Stretch">
                                        <RowDefinition />                                           
                                        <RowDefinition />
                                        <ColumnDefinition />
                                        <ColumnDefinition />
                                    <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" />

Aaron Douglas
Aaron Douglas

Total Post:20

Posted on    October-14-2013 7:52 AM

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 />

Don't want to miss updates? Please click the below button!

Follow MindStick