Silverlight 如何在不重复的情况下设置堆栈面板内部控件之间的边距?
我可以为每个堆栈面板元素指定边距,但这将是重复的。。。如果发生变化,我需要更新所有控件 有没有办法为堆栈面板定义一次 谢谢你(很抱歉我的英语不好) Xin answers非常适合您的要求,但如果您想为所有StackPanel设置更多属性,我建议您创建一种样式:Silverlight 如何在不重复的情况下设置堆栈面板内部控件之间的边距?,silverlight,silverlight-4.0,Silverlight,Silverlight 4.0,我可以为每个堆栈面板元素指定边距,但这将是重复的。。。如果发生变化,我需要更新所有控件 有没有办法为堆栈面板定义一次 谢谢你(很抱歉我的英语不好) Xin answers非常适合您的要求,但如果您想为所有StackPanel设置更多属性,我建议您创建一种样式: <Style TargetType="StackPanel" x:Key="CustomStackPanel"> <Setter Property="Margin" Value="10,12,15,20"/&
<Style TargetType="StackPanel" x:Key="CustomStackPanel">
<Setter Property="Margin" Value="10,12,15,20"/>
<Setter Property="Height" Value="50"/>
</Style>
然后像这样使用它:
<StackPanel>
<StackPanel Background="Red" Style="{StaticResource CustomStackPanel}"/>
<StackPanel Background="Green" Style="{StaticResource CustomStackPanel}"/>
<StackPanel Background="Blue" Style="{StaticResource CustomStackPanel}"/>
</StackPanel>
如果从样式中删除
x:Key
,则包含该样式的元素中的所有堆栈面板将使用该样式。如果您在app.xaml
上声明该样式,则应用程序上的所有StackPanel都将使用该样式。降级点是什么?太简单的问题?