How to learn dropdown behavior inside Expander.Header?

I would like Expander not to expand / crash when users click inside the header area. This is basically the same question as Q 1396153 , but I would appreciate a more favorable answer :)

Is there a non-invasive way to do this? I'm not sure exactly how to attach behavior to the contents of Expander.Header to prevent mouseclicks. I am ready to navigate through the contents outside the expander itself through a fixed grid layout, but I am not interested in the solution. Ideas?

XamlPad XAML example:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Expander>
    <Expander.Header><TextBlock>
        When I click this text, 
        I don't want to trigger expansion/collapse! Only when I click the 
        expander button do I want to trigger an expand/collapse!
    </TextBlock></Expander.Header>

    <Grid Background="Red" Height="100" Width="100" >
    </Grid>
    </Expander>
</Page>
+3
source share
2 answers

.

XAML:

<Expander>
    <Expander.Header>
        <TextBlock MouseDown="TextBlock_MouseDown"> 
            When I click this text,  
            I don't want to trigger expansion/collapse! Only when I click the  
            expander button do I want to trigger an expand/collapse!
                    </TextBlock>
        </Expander.Header>
    <Grid Background="Red" Height="100" Width="100" >
    </Grid>
</Expander>

:

private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
    e.Handled = true;
}
+3

, , Expander.Header Grid/fixed layout/Panel.ZIndex, , Expander.Header... . , .

0

Source: https://habr.com/ru/post/1747229/


All Articles