我将 DockPanel 添加到 RadioButton 元素,这样我就可以使用 100% 的宽度水平分布单选按钮标签、文本框和按钮。
在 DockPanel 中使用 LastChildFill="True"
拉伸(stretch)最后一个元素。如果文本框是面板中的最后一个子项,则效果很好。但是,由于按钮是最后一个元素并且具有固定宽度,因此应该拉伸(stretch)文本框。但是,没有像 2ndChildFill="True"
这样的属性。
我的代码是这样的:
<RadioButton HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<DockPanel >
<TextBlock VerticalAlignment="Center">in location:</TextBlock>
<TextBox Grid.Column="1" Margin="10,0,0,0">Path string</TextBox>
<Button HorizontalAlignment="Right"
Margin="10,0,0,0" Padding="3,0">...</Button>
</DockPanel>
</RadioButton>
它给了我这个:
有任何解决此问题的想法和提示吗?非常感谢...
最佳答案
你需要设置DockPanel.Dock
为您的元素附加属性并将 TextBox
保留为最后一个元素:
<RadioButton HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Left"
VerticalAlignment="Center"
Text="in location:" />
<Button DockPanel.Dock="Right"
Margin="10,0,0,0"
Padding="3,0"
Content="..." />
<TextBox Margin="10,0,0,0">
Path string
</TextBox>
</DockPanel>
</RadioButton>
关于c# - WPF:如何在 DockPanel 中拉伸(stretch)中间的 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14034674/