gpt4 book ai didi

c# - 使 WPF TextBox 拉伸(stretch)到可用空间而不随 Text 增长

转载 作者:行者123 更新时间:2023-11-30 20:50:45 26 4
gpt4 key购买 nike

如何使 TextBox 拉伸(stretch)到带有三个点的按钮,但当有人输入大量文本时不覆盖它?

我的 MainWindow.xaml:

<Window x:Class="Foo.Bar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:Foo.Bar.Properties"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<DockPanel>
<Label Name="lblFileName" Content="File"></Label>
<TextBox Name="txbFileName"></TextBox>
<Button Name="btnOpenFileDialog" Content="..." HorizontalAlignment="Right"></Button>
</DockPanel>
<UniformGrid>
<Button Name="btnFoo" Content="Foo"></Button>
<Button Name="btnBar" Content="Bar"></Button>
</UniformGrid>
</StackPanel>
</Grid>
</Window>

它的样子:

Screenshot

最佳答案

要拉伸(stretch)您的 TextBox,请在 DockPanel 上设置 LastChildFill="true" 并在最后添加 TextBox。

顺便说一句。如果您使用的是 DockPanel,则可以使用 DockPanel.Dock="Right" 而不是 Horizo​​ntalAlignment="Right"

<Grid>
<StackPanel>
<DockPanel LastChildFill="True">
<Label Name="lblFileName" Content="File"></Label>
<Button Name="btnOpenFileDialog" Content="..." DockPanel.Dock="Right"></Button>
<TextBox Name="txbFileName"></TextBox>
</DockPanel>
<UniformGrid>
<Button Name="btnFoo" Content="Foo"></Button>
<Button Name="btnBar" Content="Bar"></Button>
</UniformGrid>
</StackPanel>
</Grid>

关于c# - 使 WPF TextBox 拉伸(stretch)到可用空间而不随 Text 增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22320133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com