I have created a style where I have changed the expanded portion of Expander to a Popup. A section of the style is given below.
<Style
TargetType="{x:Type Expander}" x:Key="PopupExpanderStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}">
<StackPanel Orientation="Vertical">
<Border BorderBrush="{TemplateBinding BorderBrush}"
SnapsToDevicePixels="true">
<DockPanel LastChildFill="True">
<ToggleButton x:Name="HeaderSite"
DockPanel.Dock="Top"
Margin="1"
MinWidth="0"
MinHeight="0"
</DockPanel>
</Border>
<!--ContentPresenter is removed from the upper border and added a new boder for it with Popup around it-->
<Popup x:Name="PART_Popup"
AllowsTransparency="true"
Placement="Bottom"
IsOpen="True">
<Border x:Name="ExpandBorder" BorderBrush="{DynamicResource BlueBorder}" Margin="2,0,0,0"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter x:Name="ExpandSite"
Visibility="Collapsed"
Focusable="false"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</Border>
</Popup>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded"
Value="true">
<Setter Property="Visibility"
Value="Visible"
TargetName="ExpandSite"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
My Problem is when user expands the expander and then minmizes the window or goes to some other window, the Popup(Expanded portion of expander) remains visible at there place. I want to close it.....same way as ComboBox behaves.
In actual ComboBox the IsOpen is attached as given below
IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
I don't know what to do in my case.