how to make Image click through?

asked 2023-01-03T08:01:06.993+00:00
Vincent li 21 Reputation points

I wanna display an icon in a window. I want the whole window click through including icon so user can operate other application behind the window as if the window and the icon don't exist. So I create a transparent window and put an Image control on it. Now the window is click through, but user cannot pass mouse click on the icon to the applications behind it. So is it possible to set such an image click through? I have tried to set focusable=false and IsHitTestVisible=false and even set e.Handled = false PreviewMouseLeftButtonDown handler, but no luck.
<Window x:Class="WpfApp1.MainWindow"
........
ShowInTaskbar="True"
BorderBrush="Gray"
Title="WpfAppDemo"
Background="{x:Null}"
AllowsTransparency="True"
WindowStyle="None"
Height="350"
Width="400">
<Border>
<Image Width="24" Height="24" Source="/WpfApp1;component/icon.png"/>
</Border>
</Window>

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,170 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
556 questions
{count} votes

Accepted answer
  1. answered 2023-01-03T09:30:06.307+00:00
    Hui Liu-MSFT 14,556 Reputation points Microsoft Employee

    Hi,@Vincent li . Welcome. Microsoft Q&A.
    Based on my tests IsHitTestVisible=false works. You could refer to the following code.

    MainWindow.xaml:

        <Window x:Class="ImageClickThrough.MainWindow"  
    ....  
                mc:Ignorable="d" ShowInTaskbar="True"  
        BorderBrush="Gray" Background="{x:Null}"  
        AllowsTransparency="True"  
        WindowStyle="None"  
                Title="MainWindow" Height="450" Width="800">  
            <Grid>  
                <TextBlock Text="hello" Foreground="Red" FontSize="20" Height="24" Width="54" PreviewMouseDown="TextBlock_PreviewMouseDown" />  
                <Border>  
                    <Image Width="24" Height="24" Source="37.jpg"  IsHitTestVisible="False" MouseLeftButtonDown="Image_MouseDown" />  
                </Border>  
            </Grid>  
        </Window>  
    

    MainWindow.xaml.cs:
    275740-clickwindowthrough.txt

    The result:
    275894-22.gif

    ----------------------------------------------------------------------------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful