Add SubItems To Customized RadMenu Programmatically StyleSelector confusion

5 posts, 2 answers
  1. Sujiyama
    Sujiyama avatar
    3 posts
    Member since:
    Feb 2013

    Posted 12 Feb 2013 Link to this post

    Hello Telerik Team
    I need a example to add programmatically subitems to your  wpf controls example of section "appearance -> Customization".
    I try to follow your databind example. 
    My steps was 
    I Create a menuitem class and all of styles like your example
    then i add 
    <HierarchicalDataTemplate x:Key="MenuItemTemplate"
                                      ItemsSource="{Binding SubItems}">
                <TextBlock Text="{Binding Text}" />
            </HierarchicalDataTemplate>
    after that i add the radmenu
    <telerik:RadMenu x:Name="RadMenu"  ItemTemplate="{StaticResource MenuItemTemplate}"  Style="{StaticResource MenuStyle}" Grid.Row="1"   ItemContainerStyleSelector="{StaticResource MainWindowItemStyleSelector}" ItemContainerStyle="{x:Null}"  BorderThickness="0" Margin="30,0,0,0" ItemClick="OnRadMenuItemClick">
           
    All its fine until here  but when i add ItemContainerStyleSelector="{StaticResource MainWindowItemStyleSelector}"
    then subitems disappear can explain me what happend? 


    Thanks
  2. Answer
    Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 14 Feb 2013 Link to this post

    Hello Sujiyama,

    Are you sure you have implemented your ItemContainerStyleSelector correctly? In the example you are referring we are using the same approach and you can check the implementation of ItemContainerStyleSelector. If this doesn't help, could you send us the code of your style selector and declaration of the resources in your XAML. A simple project demonstrating your problem will be a great help for us.

    Kind regards,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Sujiyama
    Sujiyama avatar
    3 posts
    Member since:
    Feb 2013

    Posted 15 Feb 2013 Link to this post

    Hello Telerik Team
    Thanks for your responding. I post a example of View,ViewModel and Style Selector

    1. View

    <Window x:Class="MenuExample.MainWindow"
            xmlns:local="clr-namespace:MenuExample"
            Title="pOS"   WindowStartupLocation="CenterScreen" WindowState="Maximized"  mc:Ignorable="d"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  Height="373" Width="594">
        <Window.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0" />
                <GradientStop Color="White" Offset="1" />
            </LinearGradientBrush>
        </Window.Background>
        <Window.Resources>
             
     
           
            <!-- Example layer colors -->
            <LinearGradientBrush x:Key="HeaderBackground" EndPoint="0 1">
                <GradientStop Offset="0" Color="#868686" />
                <GradientStop Offset="1" Color="#0D0D0D" />
            </LinearGradientBrush>
            <SolidColorBrush x:Key="TitleForeground" Color="#D3D3D3" />
            <SolidColorBrush x:Key="SubTitleForeground" Color="#5ABAB6" />
            <SolidColorBrush x:Key="ApplicationBackground" Color="#FFE5E5E5" />
            <SolidColorBrush x:Key="ApplicationBorderBrush" Color="#FFB5B5B5" />
            <!-- Menu colors -->
            <LinearGradientBrush x:Key="MenuBackground" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF666666" Offset="0" />
                <GradientStop Color="#FF919191" Offset="1" />
            </LinearGradientBrush>
            <!-- TopLevel MenuItem colors -->
            <SolidColorBrush x:Key="MenuDropDownBorder" Color="#FF54BBE8" />
            <SolidColorBrush x:Key="MenuDropDownFrame" Color="#FFACACAC" />
            <SolidColorBrush x:Key="MenuDorpDownInnerBorder" Color="White" />
            <SolidColorBrush x:Key="MenuDropDownBackground" Color="#FFF7F7F7" />
            <LinearGradientBrush x:Key="MenuItemTopLevelBackground_MouseOver" EndPoint="0 1">
                <GradientStop Color="#FF7dccee" Offset="0" />
                <GradientStop Color="#FF799fd9" Offset="0.06" />
                <GradientStop Color="#FF8ebdea" Offset="0.48" />
                <GradientStop Color="#FF348bda" Offset="0.49" />
                <GradientStop Color="#FF54bce9" Offset="0.83" />
                <GradientStop Color="#FF54bce9" Offset="0.98" />
            </LinearGradientBrush>
            <!-- TopLevel section -->
            <SolidColorBrush x:Key="MenuItemSeparatorDark" Color="#FFE4E4E4" />
            <SolidColorBrush x:Key="MenuItemSeparatorLight" Color="White" />
            <!-- Title -->
            <SolidColorBrush x:Key="MenuItemTitleForeground" Color="#FF0099CC" />
            <!-- Paragraph -->
            <SolidColorBrush x:Key="MenuItemParagraphForeground" Color="#FF595959" />
            <!-- Special Link -->
            <SolidColorBrush x:Key="MenuItemSpecialLinkForeground" Color="#FF0066CC" />
            <!-- Link MenuItem colors -->
            <!-- !! Foreground coloring is hardcoded in the storyboards -->
     
            <HierarchicalDataTemplate x:Key="MenuItemTemplate"
                                      ItemsSource="{Binding SubItems}">
                <TextBlock Text="{Binding Content}" />
            </HierarchicalDataTemplate>
            <ControlTemplate x:Key="MenuItemParagraphControlTemplate" TargetType="telerik:RadMenuItem">
                <TextBlock x:Name="TextElement" Text="{Binding Content}" Foreground="{StaticResource MenuItemParagraphForeground}" TextWrapping="Wrap" FontSize="11" />
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemTitleControlTemplate" TargetType="telerik:RadMenuItem">
                <TextBlock x:Name="TextElement" Text="{Binding Content}" Foreground="{StaticResource MenuItemTitleForeground}" FontSize="16" />
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemLinkControlTemplate" TargetType="telerik:RadMenuItem">
                <TextBlock x:Name="TextElement" Text="{Binding Content}" TextDecorations="None" Foreground="#FF2C2C2C" FontSize="13" />
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="TextElement" Property="Foreground" Value="#FF0066CC" />
                        <Setter TargetName="TextElement" Property="TextDecorations" Value="Underline" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemSpecialLinkControlTemplate" TargetType="telerik:RadMenuItem" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock x:Name="MoreMark" Grid.Column="0" Text="» " TextDecorations="None" Foreground="{StaticResource MenuItemSpecialLinkForeground}" FontSize="11" />
                    <TextBlock x:Name="TextElement" Grid.Column="1" Text="{Binding Content}" TextDecorations="None" Foreground="{StaticResource MenuItemSpecialLinkForeground}" FontSize="11"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="TextElement" Property="TextDecorations" Value="Underline" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemTopLevelControlTemplate" TargetType="telerik:RadMenuItem">
                <Grid>
                    <Rectangle x:Name="BackgroundVisual" Fill="{StaticResource MenuItemTopLevelBackground_MouseOver}" Opacity="0" />
                    <TextBlock x:Name="TextElement" Text="{Binding Content}" TextDecorations="None" Foreground="White" FontWeight="Bold" Margin="20 6 40 6" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="14" />
                    <Path x:Name="DropDownArrow" Fill="White" Data="M0,0 L2,0 1,1" Stretch="Uniform" Width="7" Height="5" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="8 0 20 0" />
                    <Popup x:Name="PART_Popup" Margin="1 2 0 0" IsOpen="{TemplateBinding IsSubmenuOpen}">
                        <Border BorderBrush="{StaticResource MenuDropDownBorder}" BorderThickness="1" Background="{StaticResource MenuDropDownFrame}" Padding="6">
                            <Border Background="{StaticResource MenuDropDownBackground}" BorderBrush="{StaticResource MenuDorpDownInnerBorder}" BorderThickness="1">
                                <ItemsPresenter Margin="8 4" />
                            </Border>
                        </Border>
                    </Popup>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsKeyboardFocusWithin" Value="True">
                        <Trigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundVisual" Storyboard.TargetProperty="Opacity">
                                        <LinearDoubleKeyFrame KeyTime="00:00:00.1" Value="1" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundVisual" Storyboard.TargetProperty="Opacity">
                                        <LinearDoubleKeyFrame KeyTime="00:00:00.2" Value="0" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.ExitActions>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemTopLevelSectionControlTemplate" TargetType="telerik:RadMenuItem">
                <Grid>
                    <ItemsPresenter />
                    <Popup x:Name="PART_Popup">
                        <Rectangle />
                    </Popup>
                </Grid>
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemTopLevelSectionSeparatorControlTemplate" TargetType="telerik:RadMenuItem">
                <Border MinHeight="100" BorderThickness="1 0 0 0" Background="{StaticResource MenuItemSeparatorLight}" BorderBrush="{StaticResource MenuItemSeparatorDark}" Width="2" Margin="4 32 8 8" />
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemGalleryControlTemplate" TargetType="telerik:RadMenuItem">
                <Grid>
                    <ItemsPresenter />
                    <Popup x:Name="PART_Popup">
                        <Rectangle />
                    </Popup>
                </Grid>
            </ControlTemplate>
            <ControlTemplate x:Key="MenuItemImageControlTemplate" TargetType="telerik:RadMenuItem">
                <Image Source="{Binding Content}" Stretch="None" Cursor="Hand" HorizontalAlignment="Left" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased" />
            </ControlTemplate>
            <ControlTemplate x:Key="ParagraphImageMenuItemControlTemplate" TargetType="telerik:RadMenuItem">
                <Grid Cursor="Hand" Background="#00888888">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Image Grid.RowSpan="2" Grid.Column="0" Margin="4" HorizontalAlignment="Left" VerticalAlignment="Top" SnapsToDevicePixels="True" Source="{Binding Image}" RenderOptions.BitmapScalingMode="NearestNeighbor" RenderOptions.EdgeMode="Aliased" />
                    <TextBlock x:Name="TitleElement" Grid.Row="0" Grid.Column="1" Margin="4 4 4 -5" MaxWidth="200" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="13" Text="{Binding Title}" Foreground="Black" />
                    <TextBlock x:Name="SummaryElement" Grid.Row="1" Grid.Column="1" Margin="4 -5 4 4" MaxWidth="200" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding Summary}" FontSize="11" Foreground="{StaticResource MenuItemParagraphForeground}" />
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="TitleElement" Property="Foreground" Value="#FF0066CC" />
                        <Setter TargetName="TitleElement" Property="TextDecorations" Value="Underline" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            <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>
            <Style x:Key="MenuStyle" TargetType="telerik:RadMenu">
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="VerticalAlignment" Value="Top" />
                <Setter Property="Background" Value="Azure" />
                <Setter Property="BorderBrush" Value="Black" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="ClickToOpen" Value="False" />
            </Style>
            <Style x:Key="MenuItemTopLevelStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemTopLevelControlTemplate}" />
                <Setter Property="SeparatorTemplateKey" Value="{StaticResource MenuItemTopLevelControlTemplate}" />
                <Setter Property="SubmenuItemTemplateKey" Value="{StaticResource MenuItemTopLevelControlTemplate}" />
                <Setter Property="TopLevelHeaderTemplateKey" Value="{StaticResource MenuItemTopLevelControlTemplate}" />
                <Setter Property="TopLevelItemTemplateKey" Value="{StaticResource MenuItemTopLevelControlTemplate}" />
                <Setter Property="SubmenuHeaderTemplateKey" Value="{StaticResource MenuItemTopLevelControlTemplate}" />
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="MenuItemTopLevelSectionStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemTopLevelSectionControlTemplate}" />
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="Role" Value="Separator">
                        <Setter Property="Template" Value="{StaticResource MenuItemTopLevelSectionSeparatorControlTemplate}" />
                    </Trigger>
                </Style.Triggers>
            </Style>
            <Style x:Key="MenuItemGalleryStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemGalleryControlTemplate}" />
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="MenuItemImageStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemImageControlTemplate}" />
                <Setter Property="Margin" Value="4 4 12 4" />
            </Style>
            <Style x:Key="MenuItemParagraphStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemParagraphControlTemplate}" />
                <Setter Property="Margin" Value="4" />
                <Setter Property="MaxWidth" Value="300" />
                <Setter Property="HorizontalAlignment" Value="Left" />
            </Style>
            <Style x:Key="MenuItemTitleStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemTitleControlTemplate}" />
                <Setter Property="Margin" Value="4 3 4 1" />
                <Setter Property="MinWidth" Value="150" />
            </Style>
            <Style x:Key="MenuItemLinkStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemLinkControlTemplate}" />
                <Setter Property="Margin" Value="4 3 4 2" />
            </Style>
            <Style x:Key="MenuItemSpecialLinkStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource MenuItemSpecialLinkControlTemplate}" />
                <Setter Property="Margin" Value="4 2 4 6" />
            </Style>
            <Style x:Key="ParagraphImageMenuItemStyle" TargetType="telerik:RadMenuItem" BasedOn="{StaticResource MenuItemBaseStyle}">
                <Setter Property="Template" Value="{StaticResource ParagraphImageMenuItemControlTemplate}" />
                <Setter Property="Margin" Value="0 0 0 4" />
            </Style>
            <local:MainWindowItemStyleSelector x:Key="MainWindowItemStyleSelector" TopLevel="{StaticResource MenuItemTopLevelStyle}" TopLevelSection="{StaticResource MenuItemTopLevelSectionStyle}" Title="{StaticResource MenuItemTitleStyle}" Link="{StaticResource MenuItemLinkStyle}" SpecialLink="{StaticResource MenuItemSpecialLinkStyle}" Paragraph="{StaticResource MenuItemParagraphStyle}" Gallery="{StaticResource MenuItemGalleryStyle}" Image="{StaticResource MenuItemImageStyle}" ParagraphImage="{StaticResource ParagraphImageMenuItemStyle}" />
     
         
        </Window.Resources>
         
         
         
        <Grid Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SnapsToDevicePixels="True" Margin="0">
             
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" MinHeight="27.391" />
                <RowDefinition Height="Auto" MinHeight="34.145" />
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0"  Height="Auto">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" Opacity="0">
                        <GradientStop Color="Black" Offset="0"/>
                        <GradientStop Color="White" Offset="1"/>
                    </LinearGradientBrush>
                </Grid.Background>
                <TextBlock Margin="50,6,0,15" Text="??"  FontSize="16" Foreground="#FFC4803A" d:LayoutOverrides="GridBox" />
                <TextBlock Margin="90,6,0,0" Text="Menu Item Selector Example" Foreground="#FFFB8002" FontSize="16" d:LayoutOverrides="VerticalAlignment" FontStyle="Italic" />
     
            </Grid>
            <telerik:RadMenu x:Name="RadMenu"  ItemTemplate="{StaticResource MenuItemTemplate}"  Style="{StaticResource MenuStyle}" Grid.Row="1"   ItemContainerStyleSelector="{StaticResource MainWindowItemStyleSelector}" ItemContainerStyle="{x:Null}"  BorderThickness="0" Margin="30,0,0,0" ItemClick="OnRadMenuItemClick">
                <telerik:RadMenu.BorderBrush>
                    <SolidColorBrush Color="Black" Opacity="0"/>
                </telerik:RadMenu.BorderBrush>
                <telerik:RadMenu.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" Opacity="0">
                        <GradientStop Color="#FF161616" Offset="0.992"/>
                        <GradientStop Color="#FF5C5C5C"/>
                    </LinearGradientBrush>
                </telerik:RadMenu.Background>
            </telerik:RadMenu>
            <Border Grid.Row="2" BorderThickness="1 0 1 1" Margin="0,0,0,0">
                <Border.BorderBrush>
                    <SolidColorBrush Color="Gray" Opacity="0"/>
                </Border.BorderBrush>
                <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" Opacity="0">
                        <GradientStop Color="#FF161616" Offset="0.992"/>
                        <GradientStop Color="#FF5C5C5C"/>
                    </LinearGradientBrush>
                </Border.Background>
                <TabControl Margin="0" HorizontalAlignment="Stretch" Name="MainRegion" VerticalAlignment="Stretch" Width="Auto"  Padding="0">
                    <TabControl.BorderBrush>
                        <SolidColorBrush Color="#FF8C8E94" Opacity="0"/>
                    </TabControl.BorderBrush>
                    <TabControl.Background>
                        <SolidColorBrush Color="Transparent"/>
                    </TabControl.Background>
                    <TabControl.ItemContainerStyle>
                        <Style TargetType="{x:Type TabItem}">
                                <Setter Property="Header" Value="{Binding Content.DataContext.TabCaption}" />
                            </Style>
                        </TabControl.ItemContainerStyle>
                </TabControl>
            </Border>
        </Grid>
    </Window>
    2.Main Window Item Selector
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Windows.Controls;
    using System.Windows.Controls;
    using System.Windows;
     
     
    namespace MenuExample
    {
       public class MainWindowItemStyleSelector : StyleSelector
        {
            public Style TopLevel { get; set; }
            public Style TopLevelSection { get; set; }
            public Style Title { get; set; }
            public Style Link { get; set; }
            public Style SpecialLink { get; set; }
            public Style Paragraph { get; set; }
            public Style Gallery { get; set; }
            public Style Image { get; set; }
     
            public Style ParagraphImage { get; set; }
     
            public override Style SelectStyle(object item, DependencyObject container)
            {
                MenuExample.MenuItem menuItem = item as MenuExample.MenuItem;
                if (menuItem != null)
                {
                    switch (menuItem.Type)
                    {
                        case MenuExample.MenuItem.MenuItemTypes.TopLevel: return this.TopLevel;
                        case MenuExample.MenuItem.MenuItemTypes.TopLevelSection: return this.TopLevelSection;
                        case MenuExample.MenuItem.MenuItemTypes.Title: return this.Title;
                        case MenuExample.MenuItem.MenuItemTypes.Link: return this.Link;
                        case MenuExample.MenuItem.MenuItemTypes.SpecialLink: return this.SpecialLink;
                        case MenuExample.MenuItem.MenuItemTypes.Paragraph: return this.Paragraph;
                        case MenuExample.MenuItem.MenuItemTypes.Gallery: return this.Gallery;
                        case MenuExample.MenuItem.MenuItemTypes.Image: return this.Image;
                        default: return this.Link;
                    }
                }
                ParagraphImageMainWindowItemViewModel imageMenuItem = item as ParagraphImageMainWindowItemViewModel;
                if (imageMenuItem != null)
                {
                    return this.ParagraphImage;
                }
                return null;
            }
        }
     
    }
    3.Menu Item
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.Windows.Markup;
    using System.Collections.ObjectModel;
     
    namespace MenuExample
    {
        [ContentProperty("Items")]
        public class MenuItem : INotifyPropertyChanged
        {
            private MenuItemsCollection items;
            //private MenuItem parent;
     
     
            public MenuItem()
            {
                this.SubItems = new ObservableCollection<MenuItem>();
                 
            }
     
     
            public enum MenuItemTypes : uint { Link, SpecialLink, TopLevel, TopLevelSection, Title, Paragraph, Gallery, Image };
            public string Content { get; set; }
            public MenuItemTypes Type { get; set; }
            private bool isSeparator = false;
            public bool IsSeparator
            {
                get
                {
                    return isSeparator;
                }
                set
                {
                    isSeparator = value;
                }
            }
     
            public ObservableCollection<MenuItem> SubItems
            {
                get;
                set;
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
            public void OnPropertyChanged(string propertyname)
            {
                if (null != this.PropertyChanged)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
                }
            }
     
     
        }
    }
    4.MainWindow.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
     
    using System.Collections.ObjectModel;
    using System.Net;
     
    using Telerik.Windows.Controls;
     
    namespace MenuExample
    {
        public partial class MainWindow : Window
        {
            public MainWindowViewModel vm;
            public MainWindow()
            {
                InitializeComponent();
                vm = new MainWindowViewModel();
     
                this.DataContext = vm;
     
                this.RadMenu.ItemsSource = this.GetMenuItems();
            }
     
            private void btnSearch_Click(object sender, RoutedEventArgs e)
            {
                
            }
     
            private void btnDashboards_Click(object sender, RoutedEventArgs e)
            {
                 
                 
            }
     
            private void btnAbout_Click(object sender, RoutedEventArgs e)
            {
                //TradersView f = new TradersView();
            }
     
            private void OnRadMenuItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                //Container cont = ServiceLocator.Current.GetService<Container>();
                //cont.ShowContract("TraderView", new Dictionary<string, object>(), ContractType.View, "MainRegion");
            }
     
            public ObservableCollection<MenuExample.MenuItem> GetMenuItems()
            {
                ObservableCollection<MenuExample.MenuItem> items = new ObservableCollection<MenuExample.MenuItem>();
                ObservableCollection<MenuExample.MenuItem> fileSubItems = new ObservableCollection<MenuExample.MenuItem>();
     
                MenuExample.MenuItem m2 = new MenuExample.MenuItem();
                {
                    m2.Type = MenuExample.MenuItem.MenuItemTypes.TopLevelSection;
                    m2.Content = "Suppliers";
     
                }
                fileSubItems.Add(m2);
     
                MenuExample.MenuItem m3 = new MenuExample.MenuItem();
                {
                    m3.Content = "Traders";
                    // m3.Parent = m1;
                    m3.Type = MenuExample.MenuItem.MenuItemTypes.Link;
                }
                fileSubItems.Add(m3);
     
                MenuExample.MenuItem m1 = new MenuExample.MenuItem();
                {
                    m1.SubItems = fileSubItems;
                    m1.Content = "Commercial";
                    m1.Type = MenuExample.MenuItem.MenuItemTypes.TopLevel;
                    
                }
                items.Add(m1);
     
     
     
                return items;
            }
        }
    }

    Thanks a lot again

  5. Answer
    Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 19 Feb 2013 Link to this post

    Hi Sujiyama,

    I have implemented a new project based on your code. Please find it attached and inform us if you still have any problems or concerns.

    Kind regards,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Sujiyama
    Sujiyama avatar
    3 posts
    Member since:
    Feb 2013

    Posted 19 Feb 2013 Link to this post

    Hello Telerik
    Thanks a lot for your answer it's very helpfull for me you are the best.
    The problem was missing of
    <Setter Property="ItemsSource" Value="{Binding SubItems}"/>
    Thanks again  :D
Back to Top
UI for WPF is Visual Studio 2017 Ready