给定一个StackPanel:
<StackPanel> <TextBox Height="30">Apple</TextBox> <TextBox Height="80">Banana</TextBox> <TextBox Height="120">Cherry</TextBox> </StackPanel>
解决方法
使用边距或填充,应用于容器内的范围:
<StackPanel> <StackPanel.Resources> <Style targettype="{x:Type TextBox}"> <Setter Property="Margin" Value="0,10,0"/> </Style> </StackPanel.Resources> <TextBox Text="Apple"/> <TextBox Text="Banana"/> <TextBox Text="Cherry"/> </StackPanel>
编辑:如果您想要重新使用两个容器之间的边距,您可以将边际值转换为外部范围中的资源。
<Window.Resources> <Thickness x:Key="tbMargin">0,0</Thickness> </Window.Resources>
然后在内部作用域中引用此值
<StackPanel.Resources> <Style targettype="{x:Type TextBox}"> <Setter Property="Margin" Value="{StaticResource tbMargin}"/> </Style> </StackPanel.Resources>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。