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

RadMenuItem inside RadMenuItem

3 Answers 327 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 15 Apr 2009, 03:27 PM
Hi,

I've inherited some code and I'm just confused enough to wonder about what I'm doing anymore...  I have a menu object which has a n-level tree of menu options that I'd like to bind as the datasource for my RadMenu.  I seem to have it working properly except for the fact that I have a RadMenuItem inside another RadMenuItem because I can't figure out how else to get the click event.  I'm not an expert withi this so your patience is appreciated.

I have a HierarchicalDataTemplate as follows:

<

rad:HierarchicalDataTemplate x:Key="MenuItemDT" ItemsSource="{Binding Items}" >

 

 

   <menu:RadMenuItem Click="ctxMnuItem_Click" Header="{Binding Caption}" Icon="{Binding ImagePath, Converter={StaticResource
  
assetconv}}">

 

 

   </menu:RadMenuItem>

 

 

</rad:HierarchicalDataTemplate>

 

 

 

And my RadMenu is defined as follows:
<menu:RadMenu x:Name="mnuCtx">
   <menu:RadMenuItem ItemTemplate="{StaticResource MenuItemDT}" ItemsSource="{Binding ContextMenu.Items}">

 

 

      <menu:RadMenuItem.Icon>

 

 

          <Path Stretch="Fill" Fill="Black" Height="4" Width="8" Data="F1 M 531.107,321.943L 541.537,321.943L 536.322,328.042L
          531.107,321.943 Z" >

 

 

          </Path>

 

 

      </menu:RadMenuItem.Icon>

 

 

   </menu:RadMenuItem>

 

 

</menu:RadMenu>

 


When I run my project, everything loads and runs fine except my RadMenuItems contain RadMenuItems.  I thought about putting a "HeaderedContentControl" into "MenuItemDT" but then I don't have a place to assign my click event...

3 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 15 Apr 2009, 03:33 PM
Hi Rob,

The following example demonstrates how to handle the RadMenuItem.Click event in one place:
http://demos.telerik.com/silverlight/default.aspx#Menu/FirstLook

The example is not databound, but the code will be the same. Please, let us know if you need further assistance.

All the best,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
tl
Top achievements
Rank 1
answered on 28 Sep 2010, 02:28 PM
Hello,

I have the same problem like the original poster with a menuitem in a menuitem...The answer here from Telerik did not really helped me.

-I know how to make a flat contextmenu bound to a datasource.
-I know how to make subcontextmenus with static menuitems.

->But I don´t know how to make a subcontextmenu with databound items.
I bind a datasource on one item and I have an itemtemplate in the item for the submenuitems.
What happens is, that the subcontextmenu with the items are generated,
but I have a double focus rectangle, it seems that there is a menuitem in a menuitem (but not as a subcontextmenu)

Here is the XAML:

<telerikNavigation:RadContextMenu.ContextMenu>
      <telerikNavigation:RadContextMenu x:Name="gridContextMenu">
          <telerikNavigation:RadMenuItem Header="Element öffnen" BdlCommands:RadMenuItemClick.Command="{Binding Path=DataSource.ContactEntryActionCommand, Source={StaticResource DataContextProxy}}" BdlCommands:RadMenuItemClick.CommandParameter="OpenCurrentEntry"/>
          <telerikNavigation:RadMenuItem Header="Element löschen" BdlCommands:RadMenuItemClick.Command="{Binding Path=DataSource.ContactEntryActionCommand, Source={StaticResource DataContextProxy}}" BdlCommands:RadMenuItemClick.CommandParameter="DeleteCurrentEntry"/>
          <telerikNavigation:RadMenuItem IsSeparator="True"/>
          <telerikNavigation:RadMenuItem Header="Neue Aktion" BdlCommands:RadMenuItemClick.Command="{Binding Path=DataSource.CreateNeueAktionCommand, Source={StaticResource DataContextProxy}}" BdlCommands:RadMenuItemClick.CommandParameter="CreateNeueAktion"/>
          <telerikNavigation:RadMenuItem Header="Neue Reaktion" BdlCommands:RadMenuItemClick.Command="{Binding Path=DataSource.CreateNeueReaktionCommand, Source={StaticResource DataContextProxy}}" BdlCommands:RadMenuItemClick.CommandParameter="CreateNeueReaktion"/>
          <telerikNavigation:RadMenuItem Header="Neuer Kontakt" ItemsSource="{Binding KontaktArten}">
              <telerikNavigation:RadMenuItem.ItemTemplate>
                  <DataTemplate>
                      <telerikNavigation:RadMenuItem Header="{Binding Name}" BdlCommands:RadMenuItemClick.Command="{Binding Path=DataSource.CreateNeuesKontaktCommand, Source={StaticResource DataContextProxy}}" BdlCommands:RadMenuItemClick.CommandParameter="{Binding}"/>
                  </DataTemplate>
              </telerikNavigation:RadMenuItem.ItemTemplate>
          </telerikNavigation:RadMenuItem>
      </telerikNavigation:RadContextMenu>
  </telerikNavigation:RadContextMenu.ContextMenu>

What comes out is:

Element öffnen
Element öffnen
--------------
Neue Aktion
Neue Reaktion
Neuer Kontakt>> Neuer Report          <-This sub items have a double focus rectangle
                            Neues Telefonat
                            ....  
0
Hristo
Telerik team
answered on 30 Sep 2010, 04:07 PM
Hello tl,

You can see how to data bind multi level menu items in this example:
http://demos.telerik.com/silverlight/#Menu/DataBinding

The important part is using HierarchicalDataTemplate class where you can specify the source for the subItems:

<telerik:HierarchicalDataTemplate x:Key="MenuItemTemplate" ItemsSource="{Binding Items}" telerik:ContainerBinding.ContainerBindings="{StaticResource ContainerBindings}">
   <TextBlock Text="{Binding Text}" />
</telerik:HierarchicalDataTemplate>

This demo is for RadMenu but the same code will work for all HierarchicalItemsControls like RadContextMenu, RadTreeView, etc.

Let us know if you need additional information.

Best wishes,
Hristo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Menu
Asked by
Rob
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
tl
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or