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

Total Post:29

Points:203
Posted on    October-14-2013 7:32 AM

 C# C# 
Ratings:


 1 Reply(s)
 1084  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"> 
                <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>


Andrew Deniel
Andrew Deniel

Total Post:29

Points:203
Posted on    October-16-2013 10:19 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 />
</Grid>


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

Follow MindStick