June CTP and Transparent Windows

The June CTP of .Net Framework 3.0 was released on Friday. One new June CTP feature that I am very excited to introduce is a new property on Window called AllowsTransparency. AllowsTransparency enables you to create those semi-transparent windows and rounded-corner windows for which many of you have been asking.

I have written a small sample to illustrate some of the things to think about when creating semi-transparent windows. The central part of the sample is the following XAML:

<Window x:Class="WindowTransparency.Window1"
    Title="WindowTransparency" Height="300" Width="300"
    AllowsTransparency="True" WindowStyle="None" 
  <Border CornerRadius="50" Background="Blue" Opacity=".7">
    <Button Click="CloseWindow" Height="30" Width="100">Close Me

There are a few things to notice in this XAML. First is that I set Window.AllowsTransparency to true. Of course, as the name implies, this simply means that the Window may be made transparent (under the covers, it switches to using a layered window), it does not actually set the background to transparent. To achieve a transparent window, I set Window.Background to Transparent. Now that I have a transparent window surface, I can draw whatever content inside of it that I like. In this example, I’m simply using a Border with rounded corners to show that you can create rounded-corner windows and dialogs.

You’ll also notice that I have set Window.WindowStyle to None. For now, Windows with AllowsTransparency=true are not compatible with any of the other WindowStyles, and we expect that this will be fine for most scenarios (if you are using a transparent window, you probably don’t want the standard Win32 window chrome). Drawing your own Window chrome is easy (as an example, I’ve created a close button that I’ve hooked up to Window.Close()). Making your Window user-draggable is actually just as easy to do. The following code does it:

public Window1()
    MouseLeftButtonDown += new MouseButtonEventHandler

void Window1_MouseLeftButtonDown(object sender, 
     MouseButtonEventArgs e)

Super sexy rounded corner window

You can download the full sample here.

38 thoughts on “June CTP and Transparent Windows”

  1. Aaron,

    I don’t think you can use this stuff in partial trust – you cannot create a new Window.

  2. Sorry about the delay in responding to your questions about HW acceleration. I actually don’t know whether or not HW acceleration for layered windows made it into the June CTP. I’m hunting around for a build of Perforator that matches the June CTP so that I can check, but I’m out of the office until Wednesday 7/5, so I likely will not have an answer until then.

  3. I have tried your sample using Perforator and it seems that it is hardware rendering. Good job!

  4. I have the June CTP on XP but I have no AllowTransparency property and if I add it to the xaml is just throws an error.

    any advice?

  5. Valentin,
    Thanks for checking into HW rendering!

    What kind of error are you seeing? Does your app compile?

  6. However, as Nick Kramer pointed out a while back, HwndHost is not supported with layered windows which means that a element in the window that is navigated to a non-XAML Uri (ex: http://www.microsoft.com) is rendered fully transparent or invisible/blank. So, this AllowsTransparency=true feature is currently useless for any application that has support for loading external web content into a frame element in the XAML construction.

  7. An important note from Nick Kramer’s blog:

    “Windows Vista will support hardware accelerated layered windows, but we’re not sure about Windows XP… it’s possible we’ll need to pull support for layered window acceleration on XP”


  8. I also have the June CTP on XP and when using the AllowTransparency property I get an error.

    Is allow transparency only supported on Vista?

  9. Use AllowsTransparency, not AllowTransparency :)
    On Windows Server 2003 it works fine :)

  10. Thanks for catching that, Pavel. :) The property is indeed called AllowsTransparency, not AllowTransparency.

  11. Damian,
    If you try typing in the property name manually (without Intellisense), does your app compile? My guess is that this is just a bug in our Intellisense, and you should still be able to use the property. If your app does not build, please let me know.

  12. Yes the app compile perfectly. But… in my PC with Windows Vista (5456) the transparency effect works, in other computer with the same version of Windows Vista, the same video card, the same video drivers, the Jun Runtimes, SDK, etc, when I start the application this doesn’t appear :S
    If I disable aero and then I enabled it again, the application it works perfectly. Can you help me with that please? .
    PD: Sorry about my english, I’m from Argentina.-

  13. Rounded corners are cool but, can it take a generic shape object to define the outer shape of the window? Also, can the transparency be given a gradient or topographic contour? That would be cool! :) (forgive me if WPF can already do all of this… I’m relatively new to it)

    -Brian A.

  14. Is WindowStyle going to ultimately allow for the full set of possible styles? I’m trying to add a transparency slider to some windows in my app but the windows are really just supposed to be title bar & content, ala mIRC…nothing fancy.

  15. Keith,
    I’ll pass your feedback along to the team to consider for v2. If you could give me any more details — e.g. the analogous Win32 style that you are trying to emulate, or some screen shots of what you are trying to emulate, that would be very helpful.

  16. I’m really just going for the effect here: http://www.ishiboo.com/~nirva/Projects/froost/transparent.gif, with or without the title bar being transparent. For now, I think I’m going to draw my own title bar/border, although I have to acquaint myself with the new scheme for referencing system settings to duplicate as much of the current XP look as possible & then hook in some drag/drop & context menu.

  17. What about changing the AllowsTransparency property at runtime? Currently there is an exception thrown stating that exact thing is not possible. This might be an issue for skinning engines that might want to switch between two different window types…

  18. Pingback: ultram
  19. Pingback: Olivier Dewit
  20. I have the September CTP of .net 3.0 installed on an older XP SP2 machine and a newer Vista RC1 machine. I’m using multiple windows that have AllowsTransparency=”true”. They run fine and DragMove works, except on the Vista machine transformations and storyboards run very very slow. I hope this will be fixed in later builds but for the meantime is there a temporary fix without me having to create “fake” mdi-style children inside one window as oppose to creating multiple real windows with transparency? Thanks.

  21. I have an xbap application which is launching a WPF window with rounded corners. If i apply some tooltips or try to open some kind of popup windows inside this window, It crashes giving a message “Cannot create top level child windows” But if i remove the AllowsTransparency property of the WPF window then it works perfectly, But then i wont be getting Rounded corners. But i want to do both? Please help me!!

    (by the way no such issues in Desktop application)

  22. Hi, I am using WPF Sept CTP on XP xp2, and as suggested by you, transperancy thing works gr8, but it is not glass effect ( the vista one ) I have seen some apps (http://www.launchy.net/) which seem to give that effect in dot net 2.0 so how abt getting those same effects in WPF for XPsp2

    For vista we can do it this way : http://msdn2.microsoft.com/en-us/library/ms748975.aspx but what about XPsp2?

    I looked it up on internet and found http://blogs.msdn.com/unnir/archive/2006/03/01/541154.aspx
    however the code does not compile.. at least on my machine.. it complains about some baml file which is not found.

Comments are closed.