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

ContextMenu ItemsSource between Header and Footer Items

1 Answer 128 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Stefan asked on 12 Dec 2012, 07:42 AM
Hello,

is it possible to define an ItemsSource for a RadContextMenu only for a particular Part of the ContextMenu?
My Target is to have Header and Footer Items, which are always shown up (fixed Items) and to have Contextual Items which are filled from Item behind.
I tried it with an ItemsControl. This works so far, but if I hover one Contextual Item, the full ItemsControl is highlighted. Also the Icon is indented. Please see the attached Screenshot.

How can I remove the wrong highlighting and the Icon Indentation?

Thank you for your help!

My existing Source Code is the following (see ItemsControl):
RadContextMenu.Resources>
        <DataTemplate x:Key="SubItemTemplate">
            <telerik:RadMenuItem Header="{Binding DisplayName}" IsEnabled="{Binding Enabled}">
                <telerik:RadMenuItem.Icon>
                    <Image Stretch="Fill" MinHeight="0" MinWidth="0" MaxWidth="16" MaxHeight="16" Width="Auto" Height="Auto" Source="{Binding Image}" />
                </telerik:RadMenuItem.Icon>
            </telerik:RadMenuItem>
        </DataTemplate>
    </telerik:RadContextMenu.Resources>
 
    <!-- Region Add -->
    <telerik:RadMenuItem Header="Add" ItemsSource="{Binding Path=PossibleSubItems}" FontWeight="Bold" ItemTemplate="{StaticResource SubItemTemplate}">
        <telerik:RadMenuItem.Icon>
            <Image Width="16" Height="16" Stretch="Fill" Source="/Images/add2_16.png" />
        </telerik:RadMenuItem.Icon>
    </telerik:RadMenuItem>
 
    <telerik:RadMenuItem IsSeparator="True" />
    <!-- End Region -->
 
    <!-- FOLLOWING PART SHOWS THE CONTEXTUAL SUB-ITEMS -->
    <ItemsControl ItemsSource="{Binding ContextMenuSubItems}" ItemTemplate="{StaticResource SubItemTemplate}" />
 
    <telerik:RadMenuItem IsSeparator="True" />
 
    <!-- Region Delete -->
    <telerik:RadMenuItem Header="Delete...">
        <telerik:RadMenuItem.Icon>
            <Image Source="/Images/delete2_16.png" />
        </telerik:RadMenuItem.Icon>
    </telerik:RadMenuItem>
    <!-- End Region -->
 
    <!-- Region Rename -->
    <telerik:RadMenuItem Header="Rename" />
    <!-- End Region -->
 
</telerik:RadContextMenu>

1 Answer, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 12 Dec 2012, 12:07 PM
Hello Stefan,

There is no way to have static items and meanwhile set binding to a specific ItemsSource on the same level of RadContextMenu. With your declaration of ItemsControl in RadMenu, it is wrapped in one RadMenuItem and that's the reason why the whole control is highlighted and the icons are in incorrect place. In fact the whole ItemsControl is Header of RadMenuItem.

I suggest you to declare your items in code behind and add them to the ItemsSource. I'm sending you a simple project where this is done.

Hopefully this helps.

Kind regards,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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