【问题标题】:How to set margin between controls inside of stack panel without duplication?如何在堆栈面板内的控件之间设置边距而不重复?
【发布时间】:2012-04-28 14:00:56
【问题描述】:

我可以为每个堆栈面板元素指定边距,但这将是重复的...如果发生更改,我将需要更新所有控件...

有没有办法为堆栈面板定义一次?

谢谢

【问题讨论】:

  • 降级有什么意义?太简单的问题?

标签: silverlight silverlight-4.0


【解决方案1】:

(对不起我的英语不好)

Xin 的答案非常适合您的要求,但如果您想为所有 stackPanel 设置更多属性,我建议您创建一个样式:

 <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,则包含该样式的元素内的所有 StackPanels 将使用该样式。如果您在 app.xaml 上声明该样式,则您应用上的所有 stackPanel 都将使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2014-08-09
    • 1970-01-01
    相关资源
    最近更新 更多