Dynamic menu items

3 posts, 0 answers
  1. Daniele
    Daniele avatar
    11 posts
    Member since:
    Jul 2010

    Posted 19 Aug 2010 Link to this post


    I would need to create a menu which is partially static and partially dynamic and I created the following XAML:

    <tkctrl:HierarchicalDataTemplate x:Key="CheckableMenuItemTemplate" ItemsSource="{Binding ViewsNames}">
    <tkctrl:ContainerBinding PropertyName="IsCheckable" Binding="{Binding 'True'}"></tkctrl:ContainerBinding>
    <TextBlock Text="{Binding}"></TextBlock>
    <RowDefinition Height="Auto"></RowDefinition>
    <RowDefinition Height="*"></RowDefinition>
    <tknav:RadMenu x:Name="MainMenu" Grid.Row="0">
    <tknav:RadMenuItem Header="{Binding ConverterParameter=MainMenuActions, Converter={StaticResource AppResManConv}, Source={StaticResource AppResManConv}}">
    <tknav:RadMenuItem Header="{Binding ConverterParameter=MainMenuRefresh, Converter={StaticResource AppResManConv}, Source={StaticResource AppResManConv}}" />
    <tknav:RadMenuItem Header="{Binding ConverterParameter=MainMenuViews, Converter={StaticResource AppResManConv}, Source={StaticResource AppResManConv}}" ItemsSource="{Binding ViewsNames}" ItemTemplate="{StaticResource CheckableMenuItemTemplate}" />

    MainMenuViews menu item is the dynamic part of this menu and I would like to set IsCheckable property to 'True' statically. Also I would like to subscribe those dynamic items to Checked and Unchecked events. How can I achieve it?

  2. George
    George avatar
    1332 posts

    Posted 25 Aug 2010 Link to this post

    Hello Daniele,

    To complete your task I suggest you to set the IsCheckable property in the Style of RadMenuItem, not in the HierarchicalDataTemplate.

    Attached you can find the sample I made for you. The example illustrates how you can subscribe to the Commands and implement the described behavior. I binded the RadMenu to a ViewModel and the IsChecked property is binded with Mode ="TwoWay" to a property from this ViewModel. This allows you to implement you logic when the value is changed.

    I hope this helps!

    Kind regards,
    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
  3. Daniele
    Daniele avatar
    11 posts
    Member since:
    Jul 2010

    Posted 25 Aug 2010 Link to this post

    Thanks, I'll follow this solution and let you know.

Back to Top