2010-04-12 67 views
1

我有名爲MyUserControl的UserControl和名爲MyContainer的另一個UserControl。 如果MyUserControl放置在MyContainer中,則需要填充10,否則爲15。 不久,我想WPF:根據容器更改填充?

<MyContainer> 
    <MyUserControl> 
    Hello 
    </MyUserControl> 
</MyContainer> 

看起來像

<MyContainer> 
    <UserControl Padding="10"> 
    Hello 
    </UserControl> 
<MyContainer> 

<MyUserControl> 
Hello 
</MyUserControl> 

看起來像

<UserControl Padding="15"> 
    Hello 
</UserControl> 

回答

1

您可以嘗試parent屬性

<Style.Setters> 
    <Setter Property="Control.Padding" Value="15" /> 
</Style.Setters> 
<Style.Triggers> 
    <Trigger Property="Control.Parent" Value="MyContainer"> 
     <Setter Property="Control.Padding" Value="10" /> 
    </Trigger> 
</Style.Triggers> 

對不起,如果有任何語法或其他問題,因爲我沒有這裏的IDE。