0

I am trying to implement the ability to click through only part of a transparent background. The background image is a solid gray and has 3 circles, a rectangle, and an oval shape. The image is transparent. Button 1 appears inside of the rectangle and button 2 appears inside of the oval. When the program runs both buttons are visible but currently not clickable because the image is in a grid and added after the buttons. I would like to make only the rectangle click through so button 1 can be clicked, but still keep the image ahead of button 2 so it is not clickable.

I've searched around quite a bit for a solution but have not found what I'm looking for. This example is a dumbed down version of what I'm currently working on - but the functionality is essentially the same. Any help would be appreciated.

Xaml:

<Window x:Class="TransparentClickThrough.MainWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"             
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Button x:Name="ButtonOne" Click="ButtonOne_Click" Content="Button1" Width="50" Height="25" ></Button>
    <Button x:Name="ButtonTwo" Content="Button2" Width="50" Height="25" Margin="379,100,59,148" Click="ButtonTwo_Click"></Button>
    <Image Source="/TransparentClickThrough;component/background.png" />
</Grid>
</Window>

Code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TransparentClickThrough
{       
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();            
    }

    private void ButtonOne_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("You clicked button 1!");
    }

    private void ButtonTwo_Click(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("You clicked button 2!");
    }
}

}

background - 3 circles, rectangle, and oval are all set to transparent

This is what the program looks like when running.

Caleb
  • 23
  • 1
  • 5
  • Possible duplicate of [Irregular PNG button's click event in WPF](http://stackoverflow.com/questions/3592404/irregular-png-buttons-click-event-in-wpf) – J.H. Aug 29 '16 at 15:00

1 Answers1

0

I was able to just add a Rectangle with transparent fill to the grid. Then I added an event "MouseDown" Interaction trigger to toggle the Visibility through a DataTrigger which in turn changed the background color.

Similar to this link link

Community
  • 1
  • 1
Caleb
  • 23
  • 1
  • 5