【发布时间】:2021-10-29 05:15:57
【问题描述】:
我有一个背景为 {x:Null} 且 AllowTransparency=True 的 WPF 窗口
<Window x:Class="ClickThrough"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="SeeThru" Height="200" Width="200"
Topmost="True"
WindowStyle="None"
AllowsTransparency="True"
Background="{x:Null}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="80"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Border Background="CadetBlue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
CornerRadius="5,5,0,0" Margin="-1,0,-1,0" MouseLeftButtonDown="DragWindow">
</Border>
<Grid MouseLeftButtonUp="UIElement_OnMouseLeftButtonUp" Grid.Row="1"></Grid>
</Grid>
</Window>
我可以点击“窗口”,点击穿过窗口,底层应用程序接收到它。太棒了。不过我也希望能够处理点击事件,然后允许它传递到底层应用程序。
内部 Grid 上的事件处理程序不注册事件。
private void UIElement_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Console.WriteLine("clicked");
e.Handled = false;
}
如果我将内部网格中的背景更改为一种颜色。
<Grid MouseLeftButtonUp="UIElement_OnMouseLeftButtonUp" Grid.Row="1" Background="Aqua">
现在接收到事件,但是即使将handled 设置为false,点击也不会冒泡到底层应用程序。
这可能吗?
【问题讨论】:
标签: wpf click transparency event-passthrough