【自定义样式】ContextMenu

ContextMenu样式

对应的xaml代码:

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="{x:Type ContextMenu}">

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">

                    <Border  BorderThickness="1" Grid.Column="2" Grid.Row="1">
                        <Border    Name="Border"  BorderThickness="1" Grid.Column="2" Grid.Row="1"   Margin="5"   BorderBrush="#e2e2e2" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"  Padding="10"  CornerRadius="12">
                            <Border.Effect>
                                <!--阴影-->
                                <DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"/>
                            </Border.Effect>
                            <!--重点:右建菜单的Items-->
                            <StackPanel    IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasDropShadow" Value="true">
                            <Setter TargetName="Border" Property="Padding" Value="0,3,0,3"/>
                            <Setter TargetName="Border" Property="CornerRadius" Value="4"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>


    </Style>
</ResourceDictionary>

 

posted @ 2024-04-17 10:18  小林野夫  阅读(63)  评论(0)    收藏  举报
原文链接:https://www.cnblogs.com/cdaniu/