In Windows Forms
you can make your application semi-transparent by using Opacity
property, like so:
I'm trying to achieve the same result with WPF, but it looks impossible. If I change the Opacity
of MainWindow
I just obtain the same window with darkened content. Using AllowTransparency
creates a lot of problems because you have to rebuild your frame somehow and looks like a too complicated solution. I also tried the following approach:
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
m_Handle = (new WindowInteropHelper(this)).Handle;
if (Properties.Settings.Default.Transparency)
NativeMethods.MakeWindowTransparent(m_Handle);
}
internal static void MakeWindowTransparent(IntPtr windowHandle)
{
if (Environment.Is64BitProcess)
{
Int32 extendedStyle = GetWindowLong64(windowHandle, WindowLongIndex.ExtendedStyle).ToInt32();
SetWindowLong64(windowHandle, WindowLongIndex.ExtendedStyle, (new IntPtr(extendedStyle | 0x00000020)));
}
else
{
Int32 extendedStyle = GetWindowLong32(windowHandle, WindowLongIndex.ExtendedStyle);
SetWindowLong32(windowHandle, WindowLongIndex.ExtendedStyle, (extendedStyle | 0x00000020));
}
}
Well t doesn't work either. Seriously, why such a limitation? Is there any workaround?