IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

[ContextMenu] Comment mon style peut gérer les sous-menus ?


Sujet :

Windows Presentation Foundation

  1. #1
    Membre averti Avatar de Gregory.M
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 684
    Points : 309
    Points
    309
    Par défaut [ContextMenu] Comment mon style peut gérer les sous-menus ?
    Bonjours,


    J'ai trouvé un style de Context menu que j'ai utilisé mais je me suis rendu compte qu'il ne gérait pas les sous menu.

    Je ne sais pas trop quoi modifier pour que cela marche.


    Quelqu'un à une idée.?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <Window.Resources>
     
            <SolidColorBrush x:Key="PopupMenuBackgroundBrush" Color="#FFF6F6F6"/>
            <SolidColorBrush x:Key="MenuPressedBorderBrush" Color="#FF2B5597"/>
            <SolidColorBrush x:Key="DarkOrangeSolidBrush" Color="#FFFB8C3C"/>
     
            <!-- SubmenuItem -->
            <ControlTemplate 
        x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" 
        TargetType="{x:Type MenuItem}">
                <Border Name="Border" CornerRadius="4" Margin="2,1,2,1" BorderThickness="1" >
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Icon" MinWidth="30" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
                            <ColumnDefinition Width="13"/>
                        </Grid.ColumnDefinitions>
                        <ContentPresenter 
              Name="Icon"
              Margin="6,0,6,0"
              VerticalAlignment="Center"
              ContentSource="Icon"/>
                        <Border 
              Name="Check"  
              Width="13" Height="13" 
              Visibility="Collapsed"
              Margin="6,0,6,0" 
              Background="Black"
              BorderThickness="1"
              BorderBrush="Purple">
                            <Path 
                Name="CheckMark"
                Width="7" Height="7" 
                Visibility="Hidden" 
                SnapsToDevicePixels="False" 
                Stroke="#FFE6F0FA"
                StrokeThickness="2"
                Data="M 0 0 L 7 7 M 0 7 L 7 0" />
                        </Border>
                        <ContentPresenter 
              Name="HeaderHost"
              Grid.Column="1"
              ContentSource="Header"
              RecognizesAccessKey="True"/>
                        <TextBlock x:Name="InputGestureText"
              Grid.Column="2"
              Text="{TemplateBinding InputGestureText}"
              Margin="5,2,0,2"
              DockPanel.Dock="Right" />
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="Icon" Value="{x:Null}">
                        <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
                    </Trigger>
                    <Trigger Property="IsChecked" Value="true">
                        <Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/>
                    </Trigger>
                    <Trigger Property="IsCheckable" Value="true">
                        <Setter TargetName="Check" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
                    </Trigger>
                    <Trigger Property="IsHighlighted" Value="true">
                        <Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource DarkOrangeSolidBrush}"/>
                        <Setter Property="Background" TargetName="Border" Value="#FFFFDBAA"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource DisabledMenuForegroundBrush}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
     
            <!-- MenuItem Style -->
            <Style TargetType="{x:Type MenuItem}" x:Key="MenuItemStyle">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Style.Triggers>
                    <Trigger Property="Role" Value="SubmenuItem">
                        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
     
            <!-- ContextMenu -->
            <Style TargetType="ContextMenu" x:Key="ContextMenuStyle">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
                <Setter Property="HasDropShadow" Value="True"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ContextMenu">
                            <Border Name="Border"
                        Background="{DynamicResource PopupMenuBackgroundBrush}"
                        BorderBrush="{DynamicResource MenuPressedBorderBrush}"
                        BorderThickness="1" CornerRadius="0,8,0,8" >
                                <StackPanel IsItemsHost="True"
                              KeyboardNavigation.DirectionalNavigation="Cycle"/>
                            </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>
     
        </Window.Resources>


    D'autre part, connaissez vous un site ou je peux trouver des styles de menu, j'ai cherché mais pas trouvé.


    cordialement

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Pourquoi tu ne regardes pas avec Blend quel est le style par défaut, pour t'en servir comme base ?

  3. #3
    Membre expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Points : 3 015
    Points
    3 015
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    Pourquoi tu ne regardes pas avec Blend quel est le style par défaut, pour t'en servir comme base ?
    +1


    Pour aller plus loin dans la compréhension de ce que tu as fait jusqu'à présent :
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
            <!-- MenuItem Style -->
            <Style TargetType="{x:Type MenuItem}" x:Key="MenuItemStyle">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Style.Triggers>
                    <Trigger Property="Role" Value="SubmenuItem">
                        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
    Ici tu as défini le template pour le rôle SubmenuItem (le template étant référencé plus haut dans ton code).
    Il existe d'autres rôles comme :
    • TopLevelHeader
    • TopLevelItem
    • SubmenuHeader

    Pour avoir un style de menu complet, il faut tous les implémenter. Sinon, juste comme ça, je pense que c'est le template de SubmenuHeader qui te permettra de faire ce que tu veux


    Citation Envoyé par gregorylepacha
    D'autre part, connaissez vous un site ou je peux trouver des styles de menu, j'ai cherché mais pas trouvé.
    J'en connais pas mais il y a bien plusieurs applications "références" présentes sur le net qui utilisent des menus (le projet FamilyShow, et un autre projet reprenant le style Outlook 2007

    Après ça veut dire fouiller dans le projet (mais ça fait pas de mal ).

  4. #4
    Membre averti Avatar de Gregory.M
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 684
    Points : 309
    Points
    309
    Par défaut
    Ok merci
    je vais regarder ca

  5. #5
    Membre averti Avatar de Gregory.M
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 684
    Points : 309
    Points
    309
    Par défaut
    J'ai fait ce que tu m'as dit de faire binoo.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    <Style TargetType="{x:Type MenuItem}" x:Key="MenuItemStyle">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Style.Triggers>
                    <Trigger Property="Role" Value="SubmenuItem">
                        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
                    </Trigger>
                    <Trigger Property="Role" Value="TopLevelItem">
                        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
                    </Trigger>
                    <Trigger Property="Role" Value="SubmenuHeader">
                        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
                    </Trigger>
                    <Trigger Property="Role" Value="TopLevelHeader">
                        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>


    Cela ne me permet toujours pas de créer mon sous-menu.

  6. #6
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Points : 1 313
    Points
    1 313
    Par défaut
    voila ce que j'ai reccup dans mes fichiers (sur le theme metalicresource)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
     
    <!-- Menu, MenuItem ControlTemplates -->
     
        <Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry>
     
        <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
            <Grid SnapsToDevicePixels="true">
                <Rectangle Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="2" RadiusY="2" x:Name="Bg" />
                <Rectangle RadiusX="2" RadiusY="2" Margin="1" x:Name="InnerBorder" />
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MinWidth="24" Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup" />
                        <ColumnDefinition Width="4" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="37" />
                        <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup" />
                        <ColumnDefinition Width="17" />
                    </Grid.ColumnDefinitions>
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="1" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon" />
                    <Border Visibility="Hidden" Margin="1" x:Name="GlyphPanel" Width="22" Height="22" Background="#E6EFF4" BorderBrush="#CDD3E6" BorderThickness="1" CornerRadius="3">
                        <Path Fill="#0C12A1" FlowDirection="LeftToRight" x:Name="Glyph" Width="9" Height="11" Data="{StaticResource Checkmark}" />
                    </Border>
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" Grid.Column="2" ContentSource="Header" RecognizesAccessKey="True" />
                    <TextBlock Margin="{TemplateBinding Padding}" Text="{TemplateBinding InputGestureText}" Grid.Column="4" />
                </Grid>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="Icon" Value="{x:Null}">
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="IsChecked" Value="true">
                    <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="IsHighlighted" Value="true">
                    <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Brush_ToolBarMouseOverBackground}" />
                    <Setter Property="Stroke" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonBorder}" />
                    <Setter Property="Stroke" TargetName="InnerBorder" Value="#40FFFFFF" />
                </Trigger>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="#FF9A9A9A" />
                    <Setter Property="Background" TargetName="GlyphPanel" Value="#EEE9E9" />
                    <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#DBD6D6" />
                    <Setter Property="Fill" TargetName="Glyph" Value="#848589" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
     
        <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
     
        <Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}">
            <Setter Property="ClickMode" Value="Hover" />
            <Setter Property="MinWidth" Value="0" />
            <Setter Property="MinHeight" Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                        <DockPanel SnapsToDevicePixels="true" Background="Transparent">
                            <Rectangle Fill="Transparent" x:Name="R1" Width="1" DockPanel.Dock="Right" />
                            <Rectangle Fill="Transparent" x:Name="B1" Height="1" DockPanel.Dock="Bottom" />
                            <Rectangle Fill="Transparent" x:Name="L1" Width="1" DockPanel.Dock="Left" />
                            <Rectangle Fill="Transparent" x:Name="T1" Height="1" DockPanel.Dock="Top" />
                            <ContentPresenter HorizontalAlignment="Center" Margin="2,2,2,2" x:Name="ContentContainer" VerticalAlignment="Center" />
                        </DockPanel>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Fill" TargetName="R1" Value="{StaticResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
                                <Setter Property="Fill" TargetName="B1" Value="{StaticResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
                                <Setter Property="Fill" TargetName="L1" Value="{StaticResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" />
                                <Setter Property="Fill" TargetName="T1" Value="{StaticResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" />
                                <Setter Property="Margin" TargetName="ContentContainer" Value="3,3,1,1" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
     
        <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry>
     
        <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry>
     
        <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}" BasedOn="{x:Null}" TargetType="{x:Type ScrollViewer}">
            <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
            <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ScrollViewer}">
                        <Grid SnapsToDevicePixels="true">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Border Grid.Column="0" Grid.Row="1">
                                <ScrollContentPresenter Margin="{TemplateBinding Padding}" />
                            </Border>
                            <RepeatButton Focusable="false" Style="{StaticResource MenuScrollButton}" Command="{x:Static ScrollBar.LineUpCommand}" 
                                          CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CommandTarget}" 
                                          Grid.Column="0" Grid.Row="0">
                                <RepeatButton.Visibility>
                                    <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="0">
                                        <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                    </MultiBinding>
                                </RepeatButton.Visibility>
                                <Path Fill="{StaticResource {x:Static SystemColors.MenuTextBrushKey}}" Data="{StaticResource UpArrow}" />
                            </RepeatButton>
                            <RepeatButton Focusable="false" Style="{StaticResource MenuScrollButton}" Command="{x:Static ScrollBar.LineDownCommand}" 
                                          CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CommandTarget}" 
                                          Grid.Column="0" Grid.Row="2">
                                <RepeatButton.Visibility>
                                    <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="100">
                                        <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                                    </MultiBinding>
                                </RepeatButton.Visibility>
                                <Path Fill="{StaticResource {x:Static SystemColors.MenuTextBrushKey}}" Data="{StaticResource DownArrow}" />
                            </RepeatButton>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
     
        <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}" TargetType="{x:Type ContentControl}">
            <Border Background="#F5F5F5" BorderBrush="#FF959595" BorderThickness="1">
                <Grid>
                    <Rectangle Fill="#f1f1f1" RadiusX="2" RadiusY="2" HorizontalAlignment="Left" Margin="2" Width="25" />
                    <Rectangle Fill="#E2E3E3" HorizontalAlignment="Left" Margin="26,2,0,2" Width="1" />
                    <Rectangle Fill="White" HorizontalAlignment="Left" Margin="27,2,0,2" Width="1" />
                    <ContentPresenter Margin="1,0" Grid.ColumnSpan="2" />
                </Grid>
            </Border>
        </ControlTemplate>
     
        <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
            <Grid SnapsToDevicePixels="true">
                <Rectangle RadiusX="2" RadiusY="2" x:Name="OuterBorder" />
                <Rectangle Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="1" RadiusY="1" Margin="1" x:Name="Bg" />
                <Rectangle Margin="2" x:Name="InnerBorder" />
                <DockPanel>
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon" />
                    <Path Visibility="Collapsed" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" x:Name="GlyphPanel" VerticalAlignment="Center" Data="{StaticResource Checkmark}" />
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" ContentSource="Header" RecognizesAccessKey="True" />
                </DockPanel>
                <Popup Focusable="false" AllowsTransparency="true" HorizontalOffset="1" IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{StaticResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-1" x:Name="PART_Popup">
                    <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
                        <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{StaticResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <ScrollViewer Style="{StaticResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0" Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle" />
                            </ScrollViewer>
                        </ContentControl>
                    </Microsoft_Windows_Themes:SystemDropShadowChrome>
                </Popup>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                    <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None" />
                </Trigger>
                <Trigger Property="Icon" Value="{x:Null}">
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="IsChecked" Value="true">
                    <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                    <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5" />
                    <Setter Property="Color" TargetName="Shdw" Value="#71000000" />
                </Trigger>
                <Trigger Property="IsHighlighted" Value="true">
                    <Setter Property="Stroke" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonBorder}" />
                    <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Brush_ToolBarMouseOverBackground}" />
                    <Setter Property="Stroke" TargetName="OuterBorder" Value="#50FFFFFF" />
                    <Setter Property="Stroke" TargetName="InnerBorder" Value="#50FFFFFF" />
     
                </Trigger>
                <Trigger Property="IsKeyboardFocused" Value="true">
                    <Setter Property="Stroke" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonBorder}" />
                    <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Brush_ToolBarMouseOverBackground}" />
                    <Setter Property="Stroke" TargetName="InnerBorder" Value="#50747272" />
     
                </Trigger>
                <Trigger Property="IsSubmenuOpen" Value="true">
                    <Setter Property="Stroke" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonBorder}" />
                    <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonPressed}" />
                    <Setter Property="Stroke" TargetName="InnerBorder" Value="#50747272" />
                </Trigger>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="#FF9A9A9A" />
                    <Setter Property="Fill" TargetName="GlyphPanel" Value="#848589" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
     
        <ControlTemplate x:Key="ComponentResourceKey2" TargetType="{x:Type MenuItem}">
            <Grid SnapsToDevicePixels="true">
                <Rectangle RadiusX="2" RadiusY="2" x:Name="OuterBorder" />
                <Rectangle Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="1" RadiusY="1" Margin="1" x:Name="Bg" />
                <Rectangle Margin="2" x:Name="InnerBorder" />
                <DockPanel>
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="4,0,6,0" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon" />
                    <Path Visibility="Collapsed" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" x:Name="GlyphPanel" VerticalAlignment="Center" Data="{StaticResource Checkmark}" />
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" ContentSource="Header" RecognizesAccessKey="True" />
                </DockPanel>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="Icon" Value="{x:Null}">
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="IsChecked" Value="true">
                    <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="IsHighlighted" Value="true">
                    <Setter Property="Stroke" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonBorder}" />
                    <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Brush_ToolBarMouseOverBackground}" />
                    <Setter Property="Stroke" TargetName="OuterBorder" Value="#50FFFFFF" />
                    <Setter Property="Stroke" TargetName="InnerBorder" Value="#50FFFFFF" />
                </Trigger>
                <Trigger Property="IsKeyboardFocused" Value="true">
                    <Setter Property="Stroke" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonBorder}" />
                    <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Brush_ToolBarMouseOverBackground}" />
                    <Setter Property="Stroke" TargetName="InnerBorder" Value="#50747272" />
                </Trigger>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="#FF9A9A9A" />
                    <Setter Property="Fill" TargetName="GlyphPanel" Value="#848589" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
     
        <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry>
     
        <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
            <Grid SnapsToDevicePixels="true">
                <Rectangle Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="2" RadiusY="2" x:Name="Bg" />
                <Rectangle Stroke="Transparent" StrokeThickness="1" RadiusX="2" RadiusY="2" Margin="1" x:Name="InnerBorder" />
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MinWidth="24" Width="Auto" SharedSizeGroup="MenuItemIconColumnGroup" />
                        <ColumnDefinition Width="4" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="37" />
                        <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup" />
                        <ColumnDefinition Width="17" />
                    </Grid.ColumnDefinitions>
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="1" x:Name="Icon" VerticalAlignment="Center" ContentSource="Icon" />
                    <Border Visibility="Hidden" Margin="1" x:Name="GlyphPanel" Width="22" Height="22" Background="#E6EFF4" BorderBrush="#CDD3E6" BorderThickness="1" CornerRadius="3">
                        <Path Fill="#0C12A1" FlowDirection="LeftToRight" x:Name="Glyph" Width="9" Height="11" Data="{StaticResource Checkmark}" />
                    </Border>
                    <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}" Grid.Column="2" ContentSource="Header" RecognizesAccessKey="True" />
                    <TextBlock Visibility="Collapsed" Margin="{TemplateBinding Padding}" Text="{TemplateBinding InputGestureText}" Grid.Column="4" />
                    <Path Fill="{TemplateBinding Foreground}" Margin="4,0,0,0" VerticalAlignment="Center" Grid.Column="5" Data="{StaticResource RightArrow}" />
                </Grid>
                <Popup Focusable="false" AllowsTransparency="true" HorizontalOffset="-2" IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right" PopupAnimation="{StaticResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-3" x:Name="PART_Popup">
                    <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
                        <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{StaticResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                            <ScrollViewer Style="{StaticResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0" Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle" />
                            </ScrollViewer>
                        </ContentControl>
                    </Microsoft_Windows_Themes:SystemDropShadowChrome>
                </Popup>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSuspendingPopupAnimation" Value="true">
                    <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None" />
                </Trigger>
                <Trigger Property="IsHighlighted" Value="true">
                    <Setter Property="Stroke" TargetName="InnerBorder" Value="#D1DBF4FF" />
                </Trigger>
                <Trigger Property="Icon" Value="{x:Null}">
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="IsChecked" Value="true">
                    <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
                    <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
                </Trigger>
                <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                    <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5" />
                    <Setter Property="Color" TargetName="Shdw" Value="#71000000" />
                </Trigger>
                <Trigger Property="IsHighlighted" Value="true">
                    <Setter Property="Stroke" TargetName="Bg" Value="{DynamicResource Brush_ToolBarButtonBorder}" />
                    <Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Brush_ToolBarMouseOverBackground}" />
                </Trigger>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter Property="Foreground" Value="#FF9A9A9A" />
                    <Setter Property="Background" TargetName="GlyphPanel" Value="#EEE9E9" />
                    <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#DBD6D6" />
                    <Setter Property="Fill" TargetName="Glyph" Value="#848589" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
     
        <Style TargetType="{x:Type MenuItem}">
            <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
            <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Template" Value="{StaticResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
            <Style.Triggers>
                <Trigger Property="Role" Value="TopLevelHeader">
                    <Setter Property="Padding" Value="3,3,8,3" />
                    <Setter Property="Template" Value="{StaticResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
                </Trigger>
                <Trigger Property="Role" Value="TopLevelItem">
                    <Setter Property="Padding" Value="3,3,8,3" />
                    <Setter Property="Template" Value="{StaticResource ComponentResourceKey2}" />
                </Trigger>
                <Trigger Property="Role" Value="SubmenuHeader">
                    <Setter Property="Padding" Value="2,3,2,3" />
                    <Setter Property="Template" Value="{StaticResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
                </Trigger>
                <Trigger Property="Role" Value="SubmenuItem">
                    <Setter Property="Padding" Value="2,3,2,3" />
                </Trigger>
            </Style.Triggers>
        </Style>
     
        <Style TargetType="{x:Type Menu}">
            <Setter Property="Background" Value="{x:Null}" />
            <Setter Property="BorderBrush" Value="{DynamicResource Brush_DarkBackground}" />
            <Setter Property="Foreground" Value="{DynamicResource Brush_MenuTopLevelTextForeground}" />
        </Style>

  7. #7
    Membre averti Avatar de Gregory.M
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 684
    Points : 309
    Points
    309
    Par défaut
    Je ne comprend pas vraiment le code que tu as mit, ni la section qui me concerne

  8. #8
    Membre expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Points : 3 015
    Points
    3 015
    Par défaut
    Salut,

    Ça ne donne rien sans doute parce que tu as défini le même template pour tous les rôles. Hors il doit y avoir un intérêt et peut-être une obligation à définir des template différents...

    On peut voir que le TopLevelHeader a dans son DataTemplate une popup pour afficher les items que n'a pas SubmenuItem (ce qui parait assez logique ).

    Enfin essaie de reprendre un style par défaut comme l'a fait ikeas et travaille dessus pour obtenir ce que tu veux

Discussions similaires

  1. Réponses: 8
    Dernier message: 19/08/2013, 17h06
  2. [WS 2008 R2] DNS : Gérer les sous-domaines de mon nom de domaine externe
    Par Ang3x dans le forum Windows Serveur
    Réponses: 2
    Dernier message: 24/01/2011, 16h43
  3. Comment différencier les sous-menus d'un TMenuItem ?
    Par laclac dans le forum Débuter
    Réponses: 4
    Dernier message: 08/01/2008, 16h31
  4. Réponses: 2
    Dernier message: 26/07/2006, 10h53
  5. Réponses: 15
    Dernier message: 20/12/2005, 15h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo