WPF对齐容器中的项目 [英] WPF align items in container
本文介绍了WPF对齐容器中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个简单的xaml:
So i have thi simple xaml:
<TextBox Grid.Row="0" Grid.Column="1" Margin="10,14,10,5" BorderBrush="Magenta" BorderThickness="1" >
<TextBox.Text >
<Binding Path="Name" NotifyOnTargetUpdated="True" UpdateSourceTrigger="PropertyChanged" >
<Binding.ValidationRules>
<DataErrorValidationRule ValidatesOnTargetUpdated="False" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Border Grid.Row="1" Grid.Column="1" BorderThickness="1" BorderBrush="Lime" Margin="10, 0, 10, 0">
<DockPanel Margin="0" >
<Button Margin="0, 0, 5, 0" Width="100" Content="First" />
<Button DockPanel.Dock="Right" Width="100" Content="Second" />
</DockPanel>
</Border>
看起来是这样的:
我想以这样的方式放置按钮,即第一个按钮左对齐,第二个按钮右对齐.但是如您所见,第二个按钮和边框的右侧之间有一个空格.我怎么能杀死这个空间?预先感谢!
I would like to place buttons such a way that First button was left-aligned and secoond button was right-aligned. but as you can see there is a space between second button and right side of border. How could i kill off this space? Thank in advance!
推荐答案
这是因为(DockPanel
的)LastChildFill
在默认情况下为true,从而导致该行为.
您可以将其设置为false来解决问题:
It's because LastChildFill
(of the DockPanel
) is true by default causing that behavior.
You can set it to false to solve the problem:
<DockPanel Margin="0" LastChildFill="False">
<Button Margin="0, 0, 5, 0" Width="100" Content="First" />
<Button DockPanel.Dock="Right" Width="100" Content="Second" />
</DockPanel>
这篇关于WPF对齐容器中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文