8

我有一个 ListBox 显示一些项目,在某些模式下,我在它的顶部“加盖”了一种水印。我已经使用包含不透明度为 0.5 的 TextBlock 的边框来完成此操作。这一切都很好。

但是,我仍然希望用户能够单击 ListBox 中的项目,但是如果我单击“stamp”,它显然会吃掉单击事件,并且 ListBox 看不到它们。

我该怎么做才能防止这种情况发生?(即允许 ListBox 看到 Click 事件)

谢谢,

克雷格

4

1 回答 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>
于 2008-12-16T22:14:00.913 回答