使控件“透明”以单击事件

时间:2008-12-16 22:04:34

标签: wpf events listbox

我有一个ListBox显示一些项目,在某些模式中,我在其顶部“标记”一种水印。我用包含不透明度为0.5的TextBlock的边框完成了这个。所有这一切都很好。

但是,我仍然希望用户能够点击ListBox中的项目,但如果我点击“标记”,它显然会点击点击事件,而ListBox则看不到它们。

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

谢谢,

克雷格

1 个答案:

答案 0 :(得分:15)

您可以使用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>
相关问题