【问题标题】:How do I get a Texbox background to fit it's Margin size?如何让文本框背景适合其边距大小?
【发布时间】:2017-07-31 10:37:44
【问题描述】:

我的 UI 的一小部分是这样写的:

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

它在 StackPanel 中正确地创建从一个段到下一个段的边距,但不会用它拉伸背景颜色。看看吧。

您也不能键入传递的单列文本。我想让 TextBox 垂直扩展,这样如果你愿意的话,你基本上可以在里面写一个段落。我应该使用另一种类型的盒子吗?

【问题讨论】:

标签: wpf xaml


【解决方案1】:

您可以将其Height 设置为50,而不是将TextBox 的底部Margin 设置为50。

如果你想多行输入,你还应该将AcceptsReturn 属性设置为true

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

【讨论】:

  • 你试过这个还是发生了什么?
猜你喜欢
  • 2015-02-06
  • 1970-01-01
  • 2013-02-25
  • 2015-11-13
  • 2015-06-04
  • 2015-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多