schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!--  Separator  -->
    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
        <Setter Property="Height" Value="1"/>
        <Setter Property="Margin" Value="5 0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Separator}">
                    <Border BorderBrush="LightGray" BorderThickness="1"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <!--  Outer menu  -->
    <Style TargetType="{x:Type ContextMenu}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">
                    <!--  Here is where you change the border thickness to zero on the menu  -->
                    <Border Padding="5"  Width="{TemplateBinding Width}">
                        <Border.Effect>
                            <DropShadowEffect Color="#1e1e1e00" ShadowDepth="0" BlurRadius="5" Opacity="0.4" Direction="0"/>
                        </Border.Effect>
                        <Border x:Name="Border" CornerRadius="5" Padding="0 5" Background="White">
                            <StackPanel ClipToBounds="True" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" Orientation="Vertical" />
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="White" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 
    <!--  Outer menu items  -->
    <Style TargetType="{x:Type MenuItem}">
        <Style.Triggers>
            <Trigger Property="IsHighlighted" Value="False">
                <Setter Property="Height" Value="32" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Height" Value="32" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="#98989c" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="True">
                <Setter Property="Foreground" Value="Black" />
            </Trigger>
        </Style.Triggers>
    </Style>
 
    <!--  SubmenuItem  -->
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border Name="Border" Background="Transparent" ClipToBounds="True">
            <Grid>
                <StackPanel Orientation="Horizontal" >
                    <!--<TextBlock Text="{TemplateBinding Icon}" FontSize="16" Margin="10 0 10 0" Foreground="#595959"
                           FontFamily="{DynamicResource Iconfont}" VerticalAlignment="Center"/>-->
                    <TextBlock Text="{TemplateBinding Header}" Margin="30 0 "
                               FontSize="14" VerticalAlignment="Center" 
                               TextTrimming="CharacterEllipsis" 
                               MaxWidth="150" 
                               ToolTip="{TemplateBinding Header}"/>
                </StackPanel>
                <!--<TextBlock x:Name="Checkabled" Text="&#xeaf1;" FontSize="14" 
                           VerticalAlignment="Center" 
                           FontFamily="{DynamicResource Iconfont}" 
                           Visibility="Collapsed" 
                           Foreground="red" HorizontalAlignment="Right" Margin="0 0 10 0"/>-->
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="Background" Value="#FFDBECFF" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="#0f3c5a" />
            </Trigger>
            <Trigger Property="IsCheckable" Value="true">
                <!--<Setter Property="Visibility" TargetName="Checkabled" Value="Visible" />-->
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
 
    <!--  SubmenuHeader  -->
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border Name="Border">
            <Grid Background="Transparent">
                <StackPanel Orientation="Horizontal">
                    <!--<TextBlock Text="{TemplateBinding Icon}" FontSize="16" Margin="10 0 10 0" Foreground="#595959"
                        FontFamily="{DynamicResource Iconfont}" VerticalAlignment="Center"/>-->
                    <TextBlock Text="{TemplateBinding Header}" FontSize="14" VerticalAlignment="Center" Margin="30 0 0 0"/>
                </StackPanel>
                <Path HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5 0" 
                      Data="M 0 0 L 0 7 L 4 3.5 Z" Fill="#404040" />
                <Popup Name="Popup" AllowsTransparency="True" Focusable="False" Width="{TemplateBinding Width}"
                       HorizontalOffset="-5" IsOpen="{TemplateBinding IsSubmenuOpen}" Placement="Right" PopupAnimation="Fade">
                    <StackPanel Orientation="Horizontal">
                        <Border Width="5" Height="32" Background="White" Opacity="0.01"/>
                        <Border Padding="5">
                            <Border.Effect>
                                <DropShadowEffect Color="#1e1e1e00" ShadowDepth="0" BlurRadius="5" Opacity="0.4" Direction="0"/>
                            </Border.Effect>
                            <Border Width="{TemplateBinding Width}" Name="SubmenuBorder" Background="White">
                                <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
                            </Border>
                        </Border>
                    </StackPanel>
                </Popup>
            </Grid>
        </Border>
 
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="true">
                <Setter TargetName="Border" Property="Background" Value="#FFDBECFF" />
            </Trigger>
            <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">
                <Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="4" />
                <Setter TargetName="SubmenuBorder" Property="Padding" Value="0,3,0,3" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="#0f3c5a" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</ResourceDictionary>