私は私はまたしてもIsHitTestVisible =「false」に設定する必要はありませんだろうと思ったよりも少し複雑だった解決策を見つけた。
Download working test VS project here:
CODE
using System;
using System.Windows;
using System.Runtime.InteropServices;
using System.Windows.Interop;
namespace clickThruUI
{
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);
}
}
public partial class MainWindow : Window
{
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var hwnd = new WindowInteropHelper(this).Handle;
WindowsServices.SetWindowExTransparent(hwnd);
}
public MainWindow()
{
InitializeComponent();
}
}
}
たぶん私は新しいVSプロジェクトを作成し、唯一の大規模なテキストラベルを追加したテストとして、あなたのビュー –
@FCinを示し、透明性と「IsHitTestVisible =にすべてを設定"False"はclickイベントをキャプチャするものであってはなりません。マウスがテキストのある場所のみをブロックする問題です。 –
@YvetteColombが画像を追加しました。 –