From other post suggestions I have customized an expander so when pushed it opens a Popup with a TreeView in
Everything is working as expected, except one thing. If i click outside the popup it doesn't close even though I have set StaysOpen=False
(I have tried to replace the TreeView with a textblock, but it still doesn't work)
So what I have is a ControlTemplate for the ExpanderButton a Style for the Expander and the usage of this.
The Style
<Style x:Key="W8Expander" TargetType="{x:Type Expander}" >
<Setter Property="MinWidth" Value="120" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition x:Name="ContentRow" Height="0" />
</Grid.RowDefinitions>
<Border x:Name="Border" Grid.Row="0" BorderThickness="1" CornerRadius="2,2,0,0">
<Grid Background="{TemplateBinding Background}">
<ToggleButton x:Name="ExpanderButton" Template="{StaticResource W8ExpanderToggleButton}" Content="{TemplateBinding Header}"
IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" OverridesDefaultStyle="True" >
</ToggleButton>
</Grid>
</Border>
<Border x:Name="Content" Grid.Row="1">
<ContentPresenter Margin="0" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="False">
<Setter TargetName="ContentRow" Property="Height" Value="0" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The usage of the expander in the xaml
<Expander Name="TreeViewExpander" Style="{StaticResource W8Expander}" Grid.Row="0" Grid.Column="0" Margin="10,0,10,0" >
<Expander.Header>
<StackPanel>
<TextBlock Text="{Binding Path=ActiveReportTypeCategory.Name}"/>
<TextBlock Text="{Binding Path=ActiveReportType.Name}" Style="{DynamicResource OptionValueTextStyle}" Margin="0,-1,0,0"/>
</StackPanel>
</Expander.Header>
<Popup Name="ReportSelectionPopoUp" IsOpen="{Binding IsExpanded, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Expander}}}" StaysOpen="False" Opened="ReportSelectionPopoUp_OnOpened" PopupAnimation="Fade" Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Expander}}}" >
<TextBlock>asdf</TextBlock>
</Popup>
</Expander>
When clicking outside the popup I would expect it to close as StaysOpen=false
, however this doesn't happen. Is this due to the Opened
binding ?
Any suggestions how to get this to work ?