【问题标题】:Making a control "transparent" to click events使控件“透明”以单击事件
【发布时间】:2010-09-27 05:45:41
【问题描述】:

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

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

我必须做些什么来防止这种情况发生? (即允许 ListBox 看到 Click 事件)

谢谢,

克雷格

【问题讨论】:

  • 能否请您展示一下您是如何制作这个邮票的?
  • 见下面的例子——这就是我正在做的事情。

标签: wpf events listbox


【解决方案1】:

您可以使用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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-30
    • 2016-02-15
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多