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

RadMenuItem doesnot show seperator

1 Answer 138 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Sanket Singhvi
Top achievements
Rank 1
Sanket Singhvi asked on 04 Mar 2011, 12:11 AM
Hi,

I have declared the following template in my Resource File :
<DataTemplate x:Key="MenuItem">
<telerik:RadMenuItem 
                Margin="0"
                Padding="0"
                Header="{Binding Header}"
IsCheckable="{Binding IsCheckable}"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
IsSeparator="{Binding IsSeparator}"
IsEnabled="{Binding IsEnabled}"
Command="{Binding MenuCommand}"
/>
        </DataTemplate>

<HierarchicalDataTemplate 
x:Key="MenuItemTemplate"
ItemsSource="{Binding MenuItems}"
ItemTemplate="{StaticResource MenuItem}">
        <telerik:RadMenuItem Header="{Binding Header}"
                             IsCheckable="{Binding IsCheckable}"
                             IsChecked="{Binding IsChecked, Mode=TwoWay}"
                             IsSeparator="{Binding IsSeparator}"
                             Margin="0"
                             Padding="0"
                             IsEnabled="{Binding IsEnabled}"
                             Command="{Binding MenuCommand}"/>
</HierarchicalDataTemplate>

And I am using the above resources in RadGridView as below:
 <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu x:Name="_gridContextMenu" 
Opened="_gridContextMenu_Opened"
ItemTemplate="{StaticResource MenuItemTemplate}"
ItemsSource="{Binding ContextMenu}">
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
ContextMenu is a ObservableCollection<ContextMenuController>. 

Now Everything seems to be working except that IsSeperator doesn't work. When IsSeperator is true for a ContextMenuController it still shows as an Item occupied more space than it is supposed to be.

Look at the attached image and see how it shows the RadMenuItem which is nothing but a seperator.

Regards
Sanket

1 Answer, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 08 Mar 2011, 08:55 AM
Hi Sanket Singhvi,

HierarchicalDataTemplate is a DataTemplate and not a ControlTemplate. I have no idea why are you puttin a
<telerik:RadMenuItem
inside the DataTemplates. It means that the header of the RadMenuItem will actually be another RadMenuItem. Instead you can use a Style and Bindings inside that Style. For example you can have something like:

<Style x:Key="MenuItemBaseStyle" TargetType="telerik:RadMenuItem">
  <Setter Property="Header" Value="{Binding Content}" />
  <Setter Property="IsSeparator" Value="{Binding IsSeparator}" />
  <Setter Property="ItemsSource" Value="{Binding}" />
</Style>

And set the style as ItemContainerStyle on RadMenu or RadMenuItem.

In the upcomming 2011.Q1 we have prepared a Tic-Tac-Toe game MVVM example that will show how you can bind Commands, Icons, Headers, ItemsSource etc. on RadMenuItem.

All the best,
Pana
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
ContextMenu
Asked by
Sanket Singhvi
Top achievements
Rank 1
Answers by
Pana
Telerik team
Share this question
or