如何TextBox拉伸直到带有三个点的按钮,但在有人输入大量文本时不覆盖它?
我的主窗口.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>
Run Code Online (Sandbox Code Playgroud)
它看起来像什么

拉伸LastChildFill="true"在 DockPanel 上设置的TextBox 并在最后添加 TextBox。
顺便提一句。如果您使用DockPanel中可以使用DockPanel.Dock="Right"的替代HorizontalAlignment="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>
Run Code Online (Sandbox Code Playgroud)