RadMenuItem doesnot show seperator

2 posts, 0 answers
  1. Sanket Singhvi
    Sanket Singhvi avatar
    20 posts
    Member since:
    May 2010

    Posted 03 Mar 2011 Link to this post

    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
  2. Pana
    Admin
    Pana avatar
    748 posts

    Posted 08 Mar 2011 Link to this post

    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!
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top