0

In order to achieve a dropshadow effect, my window is slighty bigger than its main content with a transparent "border" around it. I am curious if there's a possibility to make this invisible border (coloured part in image) click-through only and prevent main content from being click-through.

enter image description here

This thread explains what to do in order to make the whole window click-through: Making a WPF window click-through, but not its controls

Is there any way to adapt this approach for what I intend do achieve?

Moldevort
  • 193
  • 1
  • 9

1 Answers1

0

Only a window with a fully transparent background is really click through. For a semi-transparent window you could for example minimize the window yourself when clicking on the shadow, e.g.:

private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if (e.OriginalSource == outer)
        WindowState = WindowState.Minimized;
}

XAML:

<Window x:Class="WpfApp1.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"
        mc:Ignorable="d"
        Title="MainWindow" Height="300" Width="300"
        AllowsTransparency="True" WindowStyle="None">
    <Window.Background>
        <SolidColorBrush Color="Red" Opacity="0.3" />
    </Window.Background>
    <Grid x:Name="outer" Background="Transparent" MouseLeftButtonDown="Grid_MouseLeftButtonDown">
        <Grid Background="Silver" Margin="10">
            <TextBlock>GUI</TextBlock>
        </Grid>
    </Grid>
</Window> 
mm8
  • 163,881
  • 10
  • 57
  • 88
  • I have thought about this solution as well, but in case window is shown on top of desktop only, it will minimise as well although it usually wouldn't. Is there a way to determine the window shown below and focus this one instead of minimising? – Moldevort Aug 13 '18 at 14:06