tags:

views:

27

answers:

1

I have UserControl named MyUserControl, and another UserControl named MyContainer. I want MyUserControl to have padding 10 if it is placed inside MyContainer and 15 otherwise. Shortly, I want

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

to look like

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

and

<MyUserControl>
 Hello
</MyUserControl>

to look like

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

You can try the Parent Property

<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>

Excuse me if there is any syntax or other problem since i've no ide here.

Veer