1

A small part of my UI is written like so:

<StackPanel>
    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Column="0">
            <TextBlock Text="Keywords" FontWeight="Bold" />
            <TextBox Padding="2" Background="#eee" Margin="0,0,0,50"/>
        </StackPanel>

        <StackPanel Grid.Column="1">
            <TextBlock Text="Exclusions" FontWeight="Bold" />
            <TextBox Padding="2" Background="#eee" Margin="0,0,0,50"/>
        </StackPanel>

    </Grid>
    <Next thingy>
</StackPanel>

It creates the margin correctly from one segment to the next in the StackPanel but does not stretch the background color with it. Take a look.

enter image description here

You also cannot type passed a single column of text. I would like to the TextBox to extend vertically so you can basically write a paragraph in it if you wanted to. Is there another type of box I should be using instead?

mm8
  • 163,881
  • 10
  • 57
  • 88
Aspen
  • 143
  • 10
  • element Margin is a space outside of element. element Background won't be applied no matter what. you should change parent Background to color that area. for TextBox to support multiline text apply attributes suggested here: http://stackoverflow.com/questions/2650144/multiline-for-wpf-textbox – ASh Mar 10 '17 at 07:21

1 Answers1

0

Instead of setting the bottom Margin of the TextBox to 50 you could set its Height to 50.

You should also set the AcceptsReturn property to true if you want to multiline input:

<StackPanel>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0">
            <TextBlock Text="Keywords" FontWeight="Bold" />
            <TextBox Padding="2" Background="#eee" Height="50" AcceptsReturn="True"/>
        </StackPanel>
        <StackPanel Grid.Column="1">
            <TextBlock Text="Exclusions" FontWeight="Bold" />
            <TextBox Padding="2" Background="#eee" Height="50" AcceptsReturn="True"/>
        </StackPanel>
    </Grid>
    <TextBlock>next...</TextBlock>
</StackPanel>
mm8
  • 163,881
  • 10
  • 57
  • 88