How add contextmenu to all RadTabItems?

4 posts, 0 answers
  1. Kristoffer
    Kristoffer avatar
    30 posts
    Member since:
    Oct 2012

    Posted 11 Dec 2012 Link to this post

    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!
  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 11 Dec 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kristoffer
    Kristoffer avatar
    30 posts
    Member since:
    Oct 2012

    Posted 11 Dec 2012 Link to this post

    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?
  5. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 12 Dec 2012 Link to this post

    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.

Back to Top