views:

1580

answers:

3

As a follow up to my previous question, I am wondering how to use transparent windows correctly. If I have set my window to use transparency, the UI will occasionally appear to stop responding. What is actually happening is that the UI simply is not updating as it should. Animations do not occur, pages do not appear to navigate; however, if you watch the debugger clicking on buttons, links, etc.. do actually work. Minimizing and restoring the window "catches up" the UI again and the user can continue working until the behavior comes back.

If I remove the transparent borders, the behavior does not occur. Am I doing something wrong or is there some other setting, code, etc... that I need to implement to work with transparent borders properly?

Here is my window declaration for the code that fails.

<Window x:Class="MyProject.MainContainer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF APplication" Height="600" Width="800"    
    xmlns:egc="ControlLibrary" Background="{x:Null}"
    BorderThickness="0"
    AllowsTransparency="True"
    MinHeight="300" MinWidth="400" WindowStyle="None" >

And the code that does not exhibit the behavior

<Window x:Class="MyProject.MainContainer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF Application" Height="600" Width="800"    
    xmlns:egc="ControlLibrary" Background="{x:Null}"
    BorderThickness="0"
    AllowsTransparency="False"
    MinHeight="300" MinWidth="400" WindowStyle="None" >
+2  A: 

Are you using .NET 3.0, or .NET 3.5 on Windows XP SP2? If so, this is a known problem with the transparent window API that has been fixed in .NET 3.5 and SP3 of XP (and I think SP1 of Vista). Basically when you set the AllowsTransparency to True, the WPF pipeline has to render in software only mode. This will cause a significant degradation in performance on most systems.

Unfortunately, the only thing you can do to fix this is to upgrade to .NET 3.0 SP1 (included in .NET 3.5), and install the appropriate service pack for Windows. Note that the transparent windows are still slower, but not nearly as bad. You can find a more in-depth discussion here.

Abe Heidebrecht
A: 

I am running on Windows XP Pro SP3 and using .NET 3.5 SP1. I have also verified that the project is targeting version 3.5 of the framework.

palehorse
In that blog post, it was stated that some video card drivers did the bitmap copy via system memory. Perhaps updating your video drivers would help.
Abe Heidebrecht
I double checked, the video drivers are already up to date with the latest. I should have mentioned that this is happening on every workstation it's been tested on (about 10 of them)
palehorse
+1  A: 

I think that I've finally found a workaround. From everything I've read this problem should not be occurring with XP SP3 & .NET 3.5 SP1, but it is.

The example from this blog post shows how to use the Win32 API functions to create an irregular shaped window, which is what I"m doing. After reworking my main window to use these techniques, things seem to be working as expected and the behavior has not returned.

It is also of note that the reason the author recommends this method is due to performance issues with WPF and transparent windows. While I believe it may be better in .NET 3.5 SP1 that it was, this was not that hard to implement and should perform better.

palehorse
According to the blog article I linked to, this may cause issues on Vista. If you don't need to support it, great. If you do, make sure to test it on Vista before going too far :)
Abe Heidebrecht