当用户在页眉区域内单击时,我想阻止扩展器展开/折叠。这基本上与 Q 1396153 相同的问题, 但我会很感激一个更有利的答案:)
有没有非侵入性的方法来做到这一点?我不确定如何将行为附加到 Expander.Header 内容以防止鼠标点击。我愿意通过固定的网格布局在扩展器本身之外的内容中 float ,但我并不热衷于解决方案。想法?
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>
最佳答案
您可以阻止应用程序处理文本框上的鼠标点击。
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;
}
关于wpf - 如何吞下 Expander.Header 中的下拉行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2915435/