一、窗体变透明,需要加三个属性:

AllowsTransparency="True"

Background="Transparent"

WindowStyle="None"


二、利用win32接口实现窗体鼠标事件穿透

Win32 API:

WPF 实现窗体鼠标事件穿透_接口实现WPF 实现窗体鼠标事件穿透_html_02

private const int WS_EX_TRANSPARENT = 0x20;

private const int GWL_EXSTYLE = -20;

[DllImport("user32", EntryPoint = "SetWindowLong")]
private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);

[DllImport("user32", EntryPoint = "GetWindowLong")]
private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);

View Code

在窗体的构造函数中调用:

WPF 实现窗体鼠标事件穿透_接口实现WPF 实现窗体鼠标事件穿透_html_02

InitializeComponent();

this.SourceInitialized += delegate
{
IntPtr hwnd = new WindowInteropHelper(this).Handle;
uint extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
};

View Code


参考文章:

​http://www.yuantk.com/weblog/a9ca4f90-56fc-4c8f-bc93-15d63fda4f57.html​