COLUMN MARGING ON A WPF GRID

C G E Mannerheim

Total Post:29

Points:203
Posted by  C G E Mannerheim
WPF 
WPF
 1194  View(s)
Ratings:
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>
  1. Aaron Douglas

    Post:20

    Points:140
    Re: Column marging on a WPF Grid

    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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!