DropShadow proper usage

Hi!
I have window

<Window x:Class = "App.WndMain" x:Name = "WindowRoot"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AllowsTransparency="True"
WindowStyle="None"
Background="Transparent"
Title="App" Height="400" Width="380"
>

And i want to have window body with rounded edges and shadow effect so i've tried
such window content:

<Border CornerRadius="15">
<Grid Height="345" Width="325" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border Width = "Auto" Height ="Auto" Style ="{StaticResource MainBorder}" >
<Border.BorderBrush>
....
</Border.BorderBrush>
<Border.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Direction="320"
ShadowDepth="10"
Softness="0.5"
Opacity="0.5"/>
</Border.BitmapEffect>
....
</Border>
</Grid>
</Border>

The whole cumbersome construction was used to provide necessary DropShadow effect.
And that worked fine, except the overall efficiency of controls that were inside that border with shadow. Everything began to work extremely slow. Especially Textbox controls.
I've read that the problem is in software rendering of shadow effect and it should be applied only to small elements.
But what i have to do in my case Is there any workaround

Thank you!




Answer this question

DropShadow proper usage

  • Dan_Brownlow

    well i think that the most simple workaround is to immitate shadow by means of additional border creation that is displaced on some distance from the border that drops shadow. For me worked the code like this:

    <Border CornerRadius="15">
    <Grid Height="345" Width="325" VerticalAlignment="Center" HorizontalAlignment="Center">
    <Grid>
    <Border
    CornerRadius="20"
    BorderThickness="0"
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Background="#44000000">
    <Border.RenderTransform>
    <TranslateTransform X="5" Y="5" />
    </Border.RenderTransform>
    </Border>
    <Border Width = "Auto" Height ="Auto" Style ="{StaticResource MainBorder}" >
    <Border.BorderBrush>
    ....
    </Border.BorderBrush>
    <Border.BitmapEffect>
    <DropShadowBitmapEffect Color="Black" Direction="320"
    ShadowDepth="10"
    Softness="0.5"
    Opacity="0.5"/>
    </Border.BitmapEffect>
    ....
    </Border>
    </Grid>
    </Grid>
    </Border>


  • Fatlabmonkey

    As the effect is applied to the content of the window, I believe the whole window uses software rendering

  • DropShadow proper usage