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

[Solved] Dynamic menu items

2 Answers 134 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Daniele
Top achievements
Rank 1
Daniele asked on 19 Aug 2010, 05:28 PM
Hi,

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

<Grid.Resources>
<tkctrl:HierarchicalDataTemplate x:Key="CheckableMenuItemTemplate" ItemsSource="{Binding ViewsNames}">
<tkctrl:ContainerBinding.ContainerBindings>
<tkctrl:ContainerBindingCollection>
<tkctrl:ContainerBinding PropertyName="IsCheckable" Binding="{Binding 'True'}"></tkctrl:ContainerBinding>
</tkctrl:ContainerBindingCollection>
</tkctrl:ContainerBinding.ContainerBindings>
<TextBlock Text="{Binding}"></TextBlock>
</tkctrl:HierarchicalDataTemplate>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<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>
<tknav:RadMenuItem Header="{Binding ConverterParameter=MainMenuViews, Converter={StaticResource AppResManConv}, Source={StaticResource AppResManConv}}" ItemsSource="{Binding ViewsNames}" ItemTemplate="{StaticResource CheckableMenuItemTemplate}" />
</tknav:RadMenu>


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?

Thanks.

2 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 25 Aug 2010, 07:02 AM
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,
George
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
0
Daniele
Top achievements
Rank 1
answered on 25 Aug 2010, 08:04 AM
Thanks, I'll follow this solution and let you know.

Regards.
Tags
Menu
Asked by
Daniele
Top achievements
Rank 1
Answers by
George
Telerik team
Daniele
Top achievements
Rank 1
Share this question
or