views:

160

answers:

1

I have a WPF Window with WindowStyle set to none. Is there some way I can force this window to drop a shadow (like the one you get when WindowStyle is not none)? I don't want to set AllowTransparency to true, because it affects the performance. And I also don't want to disable hardware rendering (I read somewhere that transparency performs better with it disabled).

+1  A: 

If you permit the window to have resize borders, by setting ResizeMode to CanResize, then you will get the OS drop shadow. You can then set the MaxWidth, MinWidth, MaxHeight, and MinHeight to values which will prevent the resize.

If you have a borderless window without a style you will have to provide all the appearance for the window in your own visual tree, including a drop shadow, since this combination of settings is the same as saying that you don't want what the OS provides.

EDIT:

From that point, if your window size is fixed, simply add the dropshadow, perhaps as a <Rectangle/> as the first element in the content of a <Canvas/>

something like this:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" AllowsTransparency="True" Background="Transparent" WindowStyle="None">
    <Canvas>
        <Rectangle Fill="#33000000" Width="100"  Height="100"/>
        <Rectangle Fill="#FFFF0000" Width="95"  Height="95" />
    </Canvas>
</Window>

Note that the Fill property of that first Rectangle is partially transparent, which you could also do with the Opacity property of the Rectangle. You could use a graphic of your own or a different shape, to customize the appearance of the drop shadow.

Note that this violates your requirement to have AllowsTransparency be False, but you have no choice: if you want transparency, you have to allow it.

Rob Perkins
How do I do the latter?
TripShock
Regarding edit: I did try something like this, but it really kills performance. I'm doing this on Windows XP, dunno about Vista/7.
TripShock