使控件对点击事件“透明”

8
我有一个ListBox显示一些项,在某些模式下,我会在其顶部“盖章”一种水印。我使用包含具有0.5不透明度的TextBlock的边框完成了此操作。这一切都很好地运作。
然而,我仍然希望用户能够点击ListBox中的项目,但如果我点击“盖章”,它显然会阻止点击事件,使ListBox无法看到。
我需要做什么来防止这种情况?(即允许ListBox看到点击事件)
谢谢,
Craig

你能展示一下你是怎么做这个印章的吗? - Szymon Rozga
看下面的例子,这基本上就是我正在做的。 - Craig Shearer
1个回答

16

您可以使用IsHitTestVisible属性来实现此操作:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ListBox>
        <ListBoxItem>a</ListBoxItem>
        <ListBoxItem>b</ListBoxItem>
        <ListBoxItem>c</ListBoxItem>
    </ListBox>
    <Border Opacity="0.2" Background="Cyan" BorderBrush="Black" BorderThickness="5" IsHitTestVisible="False" >
        <TextBlock Text="EXAMPLE" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Border>
</Grid>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接