You have to move the DataTrigger in a ControlTemplate
like this:
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander Name="Expander" IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Some Text" />
<Button Name="MyButton"
Visibility="Collapsed"
Content="Add All" />
</StackPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsExpanded, ElementName=Expander}" Value="False">
<Setter TargetName="MyButton" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Notes
I explicitly set the name for the Expander, because the construction
RelativeSource={RelativeSource Self}
points to control himself, and there in GroupItem is no propertyIsExpanded
.In Setter does not have a
TargetProperty
property, but there are TargetName.