Search code examples
wpfitemscontrolchildrengroupbox

How can I set a style trigger on the GroupBoxes of my ItemsControl without losing their current style?


When I set a style trigger on the children (GroupBoxes) of an ItemsControl the style I've previously applied to GroupBoxes is lost and it renders with default style.


Solution

  • Use the BasedOn property in the new style

    This is for using the default style

    <Style x:Key="newGroupBoxStyle" TargetType="{x:Type GroupBox}" BasedOn="{StaticResource {x:Type GroupBox}}">
      //...put triggers or whatever you want here         
     </Style>
    

    If you want to use a style based on your own style use

    ... BasedOn="{StaticResource MyGroupBoxStyleKey} ...