2012-04-28 29 views

回答

1

(對不起我的英文不好)

鑫回答非常適合你的要求,但如果你想爲所有的stackPanels設置更多的屬性,我建議你創建一個樣式:

<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將使用它。