I have a window in a WPF application with a transparent background. I want even the transparent portions to still be clickable . However, WPF automatically excludes the transparent parts from hit testing. Setting the window background to a slightly non-transparent color (eg. #01000000
) is not an option as I need the window to be fully and completely transparent . How can I achieve this?
Here is the XAML definition of my window:
<Window x:Class="ScreenDropper.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ScreenDropper"
mc:Ignorable="d"
Title="ScreenDropper" Height="40" Width="48" Topmost="True" ResizeMode="NoResize" WindowStyle="None" AllowsTransparency="True" MouseLeftButtonDown="Window_MouseLeftButtonDown" Background="Transparent" Cursor="Cross">
<Grid>
<Border BorderThickness="1" BorderBrush="Black" CornerRadius="12" HorizontalAlignment="Right" VerticalAlignment="Top" Width="24" Height="24">
<Border BorderThickness="1" BorderBrush="White" CornerRadius="12">
<Border BorderThickness="1" BorderBrush="Black" x:Name="InnerBorder" CornerRadius="12"></Border>
</Border>
</Border>
</Grid>
</Window>
尝试将 Background="Transparent" 放在窗口内的网格上,并在其上附加一个 mousedown
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.