using System; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Input; using System.Windows.Interop; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Image_MouseDown(object sender, MouseButtonEventArgs e) { MessageBox.Show("image"); } private void TextBlock_PreviewMouseDown(object sender, MouseButtonEventArgs e) { MessageBox.Show("textblock"); } protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); var hwnd = new WindowInteropHelper(this).Handle; WindowsServices.SetWindowExTransparent(hwnd); } } public static class WindowsServices { const int WS_EX_TRANSPARENT = 0x00000020; const int GWL_EXSTYLE = (-20); [DllImport("user32.dll")] static extern int GetWindowLong(IntPtr hwnd, int index); [DllImport("user32.dll")] static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle); public static void SetWindowExTransparent(IntPtr hwnd) { var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT); } }