如何吞咽 Expander.Header 内的下拉行为?

发布于 2024-09-03 01:56:45 字数 873 浏览 4 评论 0原文

当用户在标题区域内单击时,我想防止扩展器展开/折叠。这基本上与 Q 1396153 相同,但我希望有一个更有利的答案:)

有没有一种非侵入性的方法要这样做吗?我不确定如何将行为附加到 Expander.Header 内容以防止鼠标点击。我愿意通过固定的网格布局将内容浮动在扩展器本身之外,但我不热衷于该解决方案。有想法吗?

XamlPad 示例 XAML:

<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>

I would like to prevent an Expander from expanding/collapsing when users click inside the header area. This is basically the same question as Q 1396153, but I'd appreciate a more favorable answer :)

Is there a non-invasive way to do this? I am not sure exactly how to attach behavior to the Expander.Header content to prevent mouseclicks. I'm willing to float in content outside the expander itself via a fixed grid layout, but I'm not keen on the solution. Ideas?

XamlPad sample XAML:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路终见情 2024-09-10 01:56:45

您可以阻止应用程序处理文本框上的鼠标单击。

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;
}

You can stop mouse clicks on the text box from being handled by your application.

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>

Code behind:

private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
    e.Handled = true;
}
被你宠の有点坏 2024-09-10 01:56:45

我不知道这是否令人厌恶,但是,我已将内容移出 Expander.Header 并执行了一些网格/固定布局/Panel.ZIndex 技巧,以使内容看起来位于 Expander.Header 中...但事实并非如此。这可行,但太可怕了。

I don't know if this is an abomination, but, I've moved the content out of the Expander.Header and done some Grid/fixed layout/Panel.ZIndex trickery to make it appear that the content is in the Expander.Header...but it's not. This works, but it's horrible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文