Advertise with us

Column marging on a WPF Grid

Posted by  C G E Mannerheim
 2181  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" />
  1. 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>

      Modified On Apr-03-2018 05:25:34 AM