John Smitty John Smitty - 2 hours ago 2
C# Question

Ability to Select Anywhere on Expander to Expand

I am working in WPF C# and noticed that my expander will expand and collapse when when I click on the button or header (words) of the expander but will not expand when I click on the part of the expander beside the header.

The weird part is that it will collapse the expander when clicking on the same spot beside the expander.

So does anyone know how to allow the entire expander to be clicked on to expand and collapse it?

Any help is greatly appreciated!

<Expander ExpandDirection="Down" Width="Auto" Padding="4" Expanded="Expander_Expanded">
<Style TargetType="Expander">
<!--<Setter Property="IsExpanded" Value="{Binding XPath=@Name, Converter={StaticResource ExpandConverter}}" />-->
<Setter Property="IsExpanded" Value="{Binding XPath=@Expand}" />
<Setter Property="Header">
<MultiBinding Converter="{StaticResource NameConverter}">
<Binding XPath="@Name" />

<Setter Property="FontWeight" Value="Bold" />

<DataTrigger Binding="{Binding IsExpanded,RelativeSource={RelativeSource Self}}" Value="True">
<ListBox Name="itemsList"
ItemsSource="{Binding XPath=UpgradeAction}"
ItemTemplate="{StaticResource dtListItemTemplate}"
Style="{StaticResource styleListBoxUpgradeAction}"
ItemContainerStyle="{StaticResource styleListBoxItemUpgradeAction}"


The problem was that the width of the expander was not set, so it was auto. Therefore it worked when it was closing because the width, when opened, is set to the entire expander. However, it didn't work while collapsed because when collapsed, the expander width is only set to as far as the header goes. Thus, I changed the width to a fixed value and it allowed me to press anywhere on the top part of the expander to open and close it.