Column marging on a WPF Grid

Total Post:28


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

      Modified On Apr-03-2018 04:53:35 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.