tags:

views:

26

answers:

1

If i have a collection of elements in a control (e.g. a custom ItemsControl), can i set a property on all the children of that control through a style in a resource dictionary. For instance i would like to set the visibility on all those elements on a certain trigger. Is this possible decoratively?

Cheers J

+1  A: 

Sure, we can use the ItemsControl.ItemContainerStyle on an ItemsControl or any derived control to set a style for the contained elements.

<Style x:Key="customStyle">
 <Setter Property="Control.Opacity"
   Value=".5" />
 <Style.Triggers>
  <Trigger Property="Control.IsMouseOver"
     Value="True">
   <Setter Property="Control.Opacity"
     Value="1" />
  </Trigger>
 </Style.Triggers>
</Style>

<ItemsControl ItemContainerStyle="{StaticResource customStyle}">
 <ListBoxItem >Item 1</ListBoxItem>
 <sys:String>Automaticly gets Wrapped</sys:String>
 <ListBoxItem>Item 3</ListBoxItem>
</ItemsControl>
rmoore