1

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>

Thanks a lot :)

ColinE
  • 68,894
  • 15
  • 164
  • 232
Walter Fabio Simoni
  • 5,671
  • 15
  • 55
  • 80

1 Answers1

1

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>
Joe
  • 2,496
  • 1
  • 22
  • 30
  • Yes but i need to do these for each TextBox. I would like to set a margin once ! – Walter Fabio Simoni Dec 23 '12 at 22:09
  • You can apply a style on all similar controls: http://stackoverflow.com/questions/3569974/wpf-global-style or you can also wrap your textboxes into another panel, such as a `Grid`, and set the margin of the `Grid`. You would need one Grid per column or "groups" of controls. I edited my answer with the Grid idea. – Joe Dec 23 '12 at 22:28
  • Walter, did you know you need to accept the answers that worked for you by using the checkmark button? If my answer is not sufficient, let me know how I can help you further. – Joe Dec 24 '12 at 12:51