2

In Windows Forms you can make your application semi-transparent by using Opacity property, like so:

enter image description here

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?

Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
  • You might want to look at WPF Customizable Window at codeplex : http://wpfwindow.codeplex.com/ – cvraman May 16 '13 at 19:00
  • Looks like we still have the problem. I need to enable AllowTransparency and manually redraw the window borders. – Tommaso Belluzzo May 16 '13 at 19:21
  • 1
    Per [this answer](http://stackoverflow.com/a/2582379/302677) that is not possible because the default window uses an OS-dependent window chrome which can't be forced to have transparency in its client area. It's really not that hard to [build your own window chrome](http://stackoverflow.com/a/6792677/302677) though. – Rachel May 16 '13 at 19:37
  • @Rachel Euh, do you know if there's any ready-made example? I tried googling but I only find very complicated controls. – Tommaso Belluzzo May 16 '13 at 19:41
  • @Zarathos The link I posted in my previous comment was a very simple ready-made example. – Rachel May 16 '13 at 19:49
  • Damn, I have to sleep. Thanks again @Rachel! – Tommaso Belluzzo May 16 '13 at 20:10

0 Answers0