0
votes

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">
    <Expander.Style>
        <Style TargetType="Expander">
            <!--<Setter Property="IsExpanded" Value="{Binding XPath=@Name, Converter={StaticResource ExpandConverter}}"  />-->
            <Setter Property="IsExpanded" Value="{Binding XPath=@Expand}" />
            <Setter Property="Header">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource NameConverter}">
                        <Binding XPath="@Name" />
                    </MultiBinding>
                </Setter.Value>
            </Setter>

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

            <Style.Triggers>
                <DataTrigger Binding="{Binding IsExpanded,RelativeSource={RelativeSource Self}}" Value="True">
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Expander.Style>
    <ListBox Name="itemsList"
        ItemsSource="{Binding XPath=UpgradeAction}"
        ItemTemplate="{StaticResource dtListItemTemplate}"
        SelectionChanged="listItems_SelectionChanged"
        Style="{StaticResource styleListBoxUpgradeAction}"
        ItemContainerStyle="{StaticResource styleListBoxItemUpgradeAction}"
        MouseDoubleClick="itemsList_MouseDoubleClick">
    </ListBox>
</Expander>
2

2 Answers

0
votes

Have a look at the controltemplate perhaps? You could also use a click event and see if the mouse is on the header part and make it a reusable Behavior.

0
votes

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.