如何吞咽 Expander.Header 内的下拉行为?
当用户在标题区域内单击时,我想防止扩展器展开/折叠。这基本上与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以阻止应用程序处理文本框上的鼠标单击。
XAML:
隐藏代码:
You can stop mouse clicks on the text box from being handled by your application.
XAML:
Code behind:
我不知道这是否令人厌恶,但是,我已将内容移出 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.