我有一个 WPF 窗口,其中背景是 {x:Null} 和 AllowTransparency=True
<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,点击也不会冒泡到底层应用程序。
这可能吗?