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

Style for dynamically generated RadMenuItems

2 Answers 116 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 11 Jul 2012, 04:34 PM
I have a RadMenu that I need some of the drop downs to have icons, and others to have no icons. I have made two styles, one for each, and it seems to work rather well (mostly) for static menu items, but I have some items that are generated dynamically and I can't figure out how to set the "no-icon" style on those items.

By "no-icon" I mean no icon column at all. Below is the code for the sub items that I need to set the style on. The only thing that I can think of is that the generated ones have an icon column because they are sub menu items and I believe if they had children themselves they wouldn't have an icon column. If that's the case, what is the best way to make the styles so I can control which ones have an icon column?

<telerik:RadMenuItem FontSize="10.667"
              FontWeight="Bold"
              Header="Projects" 
              Style="{StaticResource RadMenuItemStyle}"
              ItemsSource="{Binding Path=Projects}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <i:InvokeCommandAction Command="{Binding RadMenuItemClickCommand}"
                           CommandParameter="{Binding Path=Projects}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <telerik:RadMenuItem.ItemTemplate>
        <telerik:HierarchicalDataTemplate>
            <telerik:ContainerBinding.ContainerBindings>
                <telerik:ContainerBindingCollection>
                    <telerik:ContainerBinding PropertyName="IsCurrent"
                                      Binding="{Binding Selected, Mode=TwoWay}"/>                                       
                </telerik:ContainerBindingCollection>
            </telerik:ContainerBinding.ContainerBindings>
            <TextBlock Text="{Binding Path=Name}" Foreground="Black" />
        </telerik:HierarchicalDataTemplate>
    </telerik:RadMenuItem.ItemTemplate>
</telerik:RadMenuItem>

2 Answers, 1 is accepted

Sort by
0
Barry
Top achievements
Rank 1
answered on 11 Jul 2012, 06:43 PM
I put color backgrounds on everything in the styles and learned the difference between top level headers and items and sub level headers and items. So I added the style to the dynamic items by itemcontainerstyle.

I guess I just didn't know what was a header and what was an item and when.
0
Accepted
Todor
Telerik team
answered on 12 Jul 2012, 12:33 PM
Hi Barry,

Please find attached a sample project illustrating our suggested approach for customizing the RadMenuItems and meanwhile if you have more questions about RadMenuItem styling you can check this article.

Hope that helps.

Kind regards,
Todor
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
Menu
Asked by
Barry
Top achievements
Rank 1
Answers by
Barry
Top achievements
Rank 1
Todor
Telerik team
Share this question
or