This is a migrated thread and some comments may be shown as answers.

Rounded Corner RadContextMenu Style for Submenu

1 Answer 438 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Nag
Top achievements
Rank 1
Nag asked on 26 Apr 2013, 03:56 PM
I couldn't able to apply rounded corners to the SubMenu's in the RadContextMenu. I do like to know how to set the minwidth for submenu just like in the TopLevelMenu and How to change the highlightcolor. Any help would be great. Thank you in advance.
<Window.Resources>       
        <Style x:Key="MenuItemStyle" TargetType="{x:Type telerik:RadMenuItem}">
            <Setter Property="Icon" Value="{Binding Icon}" />
            <Setter Property="IsSeparator" Value="{Binding IsSeparator}" />           
        </Style>
        <Style x:Key="ContextMenuStyle" TargetType="telerik:RadContextMenu">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:RadContextMenu">
                        <Border CornerRadius="5" BorderBrush="Gray" BorderThickness="1" Background="White" SnapsToDevicePixels="True">
                            <ItemsPresenter />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Border Background="Gray" >
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu x:Name="textcontext" IconColumnWidth="0" MinWidth="150" 
                                        Style="{StaticResource ContextMenuStyle}" HorizontalAlignment="Right"
                                        NotifyOnHeaderClick="True" ItemContainerStyle="{StaticResource MenuItemStyle}" ItemsSource="{Binding}" >
                    <telerik:RadMenuItem Header="New" />
                    <telerik:RadMenuItem IsSeparator="True" />
                    <telerik:RadMenuItem Header="Edit" >
                        <telerik:RadMenuItem Header="New" />
                        <telerik:RadMenuItem IsSeparator="True" />
                        <telerik:RadMenuItem Header="Edit">
                            <telerik:RadMenuItem Header="New" />
                            <telerik:RadMenuItem IsSeparator="True" />
                            <telerik:RadMenuItem Header="Edit"/>
                            <telerik:RadMenuItem Header="Delete" />
                            <telerik:RadMenuItem Header="Select" />
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem Header="Delete" />
                        <telerik:RadMenuItem Header="Select" />
                    </telerik:RadMenuItem>                                    
                    <telerik:RadMenuItem Header="Delete" />
                    <telerik:RadMenuItem IsSeparator="True" />
                    <telerik:RadMenuItem Header="Select" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
        </Border>
    </Grid>



1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 01 May 2013, 08:22 AM
Hi Nag,

I see that you have added round corners to RadContextMenu but in order to have round corners for all sub menus you have to modify the template of RadMenuItem. RadMenuItem have four different templates - TopLevelHeaderTemplate for items in RadMenu that have sub menus, TopLevelItemTemplate for items in RadMenu that doesn't have sub menus, SubMenuHeaderTemplate - for items in RadContextMenu or other RadMenuItem that have sub menus and SubMenuItemTemplate - for items in RadContextMenu or other RadMenuItem that doesn't have sub menus.
In your case you have to modify SubMenuHeaderTemplate where the Popup is placed and add the round corner and change the highlight. You should also modify SubMenuItemTemplate to change the highlight for menu items that doesn't have sub menus.

I've prepared sample project demonstrating all changes. You can search for Modified Code commented section in XAML to see which parts are modified compared to the original template.
In the project I've added all templates but if you don't need them you can remove them.

You can read more about RadMenu, RadContextMenu and RadMenuItem customization here:
http://www.telerik.com/help/silverlight/radmenu-styling-and-templates-styling-radmenu.html
http://www.telerik.com/help/silverlight/radcontextmenu-styles-and-templates-styling-the-context-menu.html
http://www.telerik.com/help/silverlight/radmenu-styling-and-appearance-styling-radmenuitem.html

Let us know if this helps you.

Kind regards,
Hristo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ContextMenu
Asked by
Nag
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or