简体   繁体   English

如何在WPF中使文本框填充其他项目之间的水平空间?

[英]How do I make a textbox in WPF fill the horizontal space between other items?

I'm trying to have a stackpanel of radio buttons on the left, a button on the right, both of fixed width, and a text box between them that stretches to fill the space as the window is resized. 我试图在左边有一个单选按钮的堆栈面板,在右边有一个固定宽度的单选按钮,以及它们之间的文本框,它们在调整窗口大小时会拉伸以填充空间。

This is what seems like should work: 这似乎应该工作:

<Grid >
  <Grid.ColumnDefinitions>
    <ColumnDefinition />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition />
  </Grid.ColumnDefinitions>
  <StackPanel HorizontalAlignment="Left">
    <RadioButton GroupName="FibOptions" IsChecked="True">Term Closest To N:</RadioButton>
    <RadioButton GroupName="FibOptions">Nth Term:</RadioButton>
  </StackPanel>
  <TextBox x:Name="FibInput" Grid.Column="1" />
  <Button Grid.Column="2" x:Name="FibGen" HorizontalAlignment="Right">Generate</Button>
</Grid>

But the above results in a tiny text box that's basically a vertical line right in the middle of the area. 但是以上结果导致了一个很小的文本框,该文本框基本上是该区域中间的垂直线。 Any help with this? 有什么帮助吗?

Set the column width to * , which tells it to fill the remaining space, and set the other two to auto : 将列宽设置为* ,告诉它填充剩余空间,并将其他两个设置为auto

                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="auto" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM