Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF overriding ContextMenu style - DropShadowEffect not working

I want to override the ContextMenu's style.
Here's my style:

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="#E7E8EC" />
<SolidColorBrush x:Key="SolidBorderBrush" Color="#CCCEDB" />
<Color x:Key="DropShadowColor">#808080</Color>

<Style TargetType="{x:Type ContextMenu}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="FontFamily" Value="Segoe UI"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ContextMenu}">
                <Border Name="Border" Background="{StaticResource WindowBackgroundBrush}" BorderBrush="{StaticResource SolidBorderBrush}" BorderThickness="1" >
                    <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
                    <Border.Effect>
                        <DropShadowEffect Color="{StaticResource DropShadowColor}" Opacity="0.60" ShadowDepth="4"/>
                    </Border.Effect>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I dont know why, but the shadow is not working (I dont see the shadow).
How can I solve it?

like image 587
Ron Avatar asked Oct 18 '25 14:10

Ron


1 Answers

of course you won't see the shadow, because it is applied to the top-most element in the visual tree. give some margin to your border and you will see the shadow effect.

Regards

like image 179
abdelkarim Avatar answered Oct 22 '25 04:10

abdelkarim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!