May 27, 2011

WPF Invisible Window

Since it took me a while searching, and trial/error to find out how to do this I thought I’d post a code snippet.  My initial attempt gave a small circle, and later attempts a black dot.  Eventually I came across an article on creating a borderless window that did the trick.

So here’s the final code snippet:

var tempParent = new Window
{
   
Height = 0,
   
Width = 0,
   
Top = 200,
   
Left = 200,
   
WindowStartupLocation = WindowStartupLocation.Manual,
   
WindowStyle = WindowStyle.None,
   
ShowInTaskbar = false,
   
Background = Brushes.Transparent,
   
AllowsTransparency = true
};

Top/Left/WindowStartupLocation aren’t needed.  I was using them to try positioning an OpenFileDialog relative to this invisible Window.  The trick works on Windows 7, but sadly not on XP, which still opens the dialog centre screen.

0 comments: