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

How add contextmenu to all RadTabItems?

3 Answers 248 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Kristoffer
Top achievements
Rank 1
Kristoffer asked on 11 Dec 2012, 03:13 PM
I can add a context menu to my tab items as shown below. However, I want all RadTabItems to have this menu - keeping their current theme (user is allowed to switch between themes). How can this be done without repeating this code for each tab item?

<telerik:RadTabControl x:Name="tabControl" Grid.Row="1" VerticalAlignment="Top"
                               DisplayMemberPath="Content" DropDownDisplayMode="Visible" ScrollMode="Viewport">
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu>
                    <telerik:RadMenuItem Header="Do Stuff" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>

Thanks!

3 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 11 Dec 2012, 03:47 PM
Hello Kristoffer,

If you set RadContextMenu on your RadTabControl you will have only one contextmenu for all items:
<telerik:RadTabControl x:Name="tabControl" Grid.Row="1" VerticalAlignment="Top"
                        DisplayMemberPath="Content" DropDownDisplayMode="Visible" ScrollMode="Viewport">
    <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu>
            <telerik:RadMenuItem Header="Do Stuff" />
        </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>
    <telerik:RadTabItem Header="TabItem 1"/>
    <telerik:RadTabItem Header="TabItem 2"/>
    <telerik:RadTabItem Header="TabItem 3"/>
    <telerik:RadTabItem Header="TabItem 4"/>
</telerik:RadTabControl>

Each RadTabItem will show the same RadContextMenu so if you change something in it, you will see the changed version no matter on which RadTabItem you open it.

If this is not the case you want, please give us more information exactly what you need. Looking forward to hearing from you.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Kristoffer
Top achievements
Rank 1
answered on 11 Dec 2012, 04:18 PM
Thanks. But that also shows the context menu when right clicking outside the tabs.

I want to show a context menu for the current tab item, just like you do in Visual Studio (where the context menu does indeed not show when clicking outside the tabs). The thing is that my tabs will have the same menu items, so it makes sense to put it on one place.

Style? DataTemplate? ContentTemplate?
0
Rosen Vladimirov
Telerik team
answered on 12 Dec 2012, 07:27 AM
Hi Kristoffer,

In this case you can use the code below:
<Window.Resources>
    <telerik:RadContextMenu x:Key="CommonContextMenu">
        <telerik:RadMenuItem Header="CommonItem1"/>
    </telerik:RadContextMenu>
    <Style TargetType="telerik:RadTabItem">
        <Setter Property="telerik:RadContextMenu.ContextMenu" Value="{StaticResource CommonContextMenu}"/>
    </Style>
</Window.Resources>
<Grid>
    <telerik:RadTabControl x:Name="tabControl" Grid.Row="1" VerticalAlignment="Top"
                            DisplayMemberPath="Content" DropDownDisplayMode="Visible" ScrollMode="Viewport">
        <telerik:RadTabItem Header="TabItem 1" Background="AliceBlue"/>
        <telerik:RadTabItem Header="TabItem 2"/>
        <telerik:RadTabItem Header="TabItem 3"/>
        <telerik:RadTabItem Header="TabItem 4"/>
    </telerik:RadTabControl>
</Grid>

Hopefully this helps!

Regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ContextMenu
Asked by
Kristoffer
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Kristoffer
Top achievements
Rank 1
Share this question
or