WPF使透明窗口背景可单击

时间:2019-07-17 16:43:26

标签: c# wpf xaml

我在WPF应用程序中有一个透明背景的窗口。我甚至希望透明部分仍然仍可点击。但是,WPF会自动将透明部分排除在点击测试之外。将窗口背景设置为略微不透明的颜色(例如#01000000)不是一种选择,因为我需要使窗口完全透明。我该如何实现?

这是我的窗口的XAML定义:

<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>

1 个答案:

答案 0 :(得分:-1)

尝试将Background =“ Transparent”放置在窗口内的网格上,然后将鼠标悬停在该网格上