Search code examples
c#silverlightcode-behind

Dynamically add dropshadow effect to Silverlight border?


I would like to dynamically add a DropShadowEffect to my Silverlight border but cant figure out the C# syntax...

                <Border BorderThickness="1"
                        CornerRadius="5"
                        Background="{StaticResource PanelBackground}"
                        BorderBrush="{StaticResource PanelBorderBrush}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        Margin="0,8,0,0"
                        Width="250">
                    <Border.Effect>
                        <DropShadowEffect />
                    </Border.Effect>
                </Border>

I can create the border fine its the Border.Effect I am having trouble with.

Paul.


Solution

  • System.Windows.Media.Effects.DropShadowEffect dropShadowEffect = new System.Windows.Media.Effects.DropShadowEffect();
    dropShadowEffect.Opacity = 0.25;
    dropShadowEffect.ShadowDepth = 5;
    dropShadowEffect.BlurRadius = 10;
    dropShadowEffect.Color = Colors.Black;
    this.image.Effect = dropShadowEffect;
    

    source http://msdn.microsoft.com/en-us/library/system.windows.media.effects.dropshadoweffect.aspx

    and

    <Border Name="border">
                <Border.Effect>
                    <DropShadowEffect/>
                </Border.Effect>
            </Border>
    
        this.border.Effect = dropShadowEffect;