Sub context menu dynamicly

24 posts, 0 answers
  1. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 11 May 2009 Link to this post

    Hi,
    I have a context menu, in run time I added to first item in the context menu -   Sub Context menu.(dynamicly)
    the sub context menu created dynamicly when the user press on the first item in the context menu.
    I want that on the first item in the context menu showen arrow icon always, (in order to the user know that have sub context menu to the item.)
    I try to create sub context menu demo when the context menu create, the icon was show , but the event of the first item in the context menu be lost.
    How can I do it???(to show the arrow icon always)
    Thanks.
  2. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 15 May 2009 Link to this post

    Hi ruty,

    We don't have such a property, but I found a workaround for you. You have to set the same template as the one we use for menu items having children. This is done like:
            void item1_Loaded(object sender, RoutedEventArgs e) 
            { 
                var menuItem = sender as RadMenuItem; 
                menuItem.SubmenuItemTemplateKey = menuItem.SubmenuHeaderTemplateKey; 
                menuItem.Template = menuItem.SubmenuHeaderTemplateKey; 
                menuItem.ApplyTemplate(); 
            } 

     I have attached a simple project which shows how it is done. If you need more help I will be glad to help you further.

    Regards,
    Boyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 17 May 2009 Link to this post

    Thenks for your answer.
    Its very help me.
    but, when I implement the answer. 
    I get the context menu with the arrow icon in the correct places .
    I have 10 items in the context menu and on 3 from them it have arrow icon.
    if I implement the answer on the first item in the context menu ,the item deleted!!!!!!(from the context menu).
    and if I implement the answer on the other items it is ok.
    Can you help me???
    Thenks.
  5. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 17 May 2009 Link to this post

    And when I debug the progrem I look that :

     

    RadMenuItem

     

    menuItem = item;

     

    menuItem.SubmenuItemTemplateKey = menuItem.SubmenuHeaderTemplateKey;

    menuItem.Template = menuItem.SubmenuHeaderTemplateKey;

    menuItem.ApplyTemplate();



    in the first item this code get null:

    menuItem.SubmenuItemTemplateKey = menuItem.SubmenuHeaderTemplateKey;
    and in the other items it is get value;

    How can I do it???

  6. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 18 May 2009 Link to this post

    Hi ruty,

    I was not able to reproduce the issues. Can you please open a support ticket and attach a simple project so I can investigate further and try to find what the problem is.

    All the best,
    Boyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 20 May 2009 Link to this post

    Thenks for your replys.
    I added icon to your simple project (that you attached):

    item1.Icon =

    new Image() { Source = new BitmapImage(new Uri("filter.png", UriKind.Relative)) };
    and in the function:"item1_loded" the progrem failed  in the line:

     

    menuItem.ApplyTemplate();

    I attache the code:(I don't now how I attache project to the form :( .

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Net;  
    using System.Windows;  
    using System.Windows.Controls;  
    using System.Windows.Documents;  
    using System.Windows.Input;  
    using System.Windows.Media;  
    using System.Windows.Media.Animation;  
    using System.Windows.Shapes;  
    using Telerik.Windows.Controls;  
    using Telerik.Windows;  
    using System.Windows.Media.Imaging;  
     
    namespace ContextMenuDynamicaly  
    {  
        public partial class Page : UserControl  
        {  
            public Page()  
            {  
                InitializeComponent();  
                Loaded += new RoutedEventHandler(Page_Loaded);  
     
            }  
     
            void Page_Loaded(object sender, RoutedEventArgs e)  
            {  
                RadContextMenu context = new RadContextMenu();  
                context.StaysOpen = true;  
                //context.EventName = "MouseLeftButtonDown";  
                RadMenuItem item1 = new RadMenuItem() { Header = "Copy" };  
                Image icon = new Image();  
                icon.VerticalAlignment = VerticalAlignment.Center;  
                icon.IsHitTestVisible = false

     
                item1.Icon = new Image() { Source = new BitmapImage(new Uri("filter.png", UriKind.Relative)) };  


                RadMenuItem item2 = new RadMenuItem() { Header = "Paste" };  
                item1.Loaded += new RoutedEventHandler(item1_Loaded);  
                context.Items.Add(item1);  
                context.Items.Add(item2);  
     
                context.AddHandler(RadMenuItem.ClickEvent, new RoutedEventHandler(OnMenuItemClicked));    
                RadContextMenu.SetContextMenu(but, context);  
            }  
     
            void item1_Loaded(object sender, RoutedEventArgs e)  
            {  
                var menuItem = sender as RadMenuItem;  
                menuItemmenuItem.SubmenuItemTemplateKey = menuItem.SubmenuHeaderTemplateKey;  
                menuItemmenuItem.Template = menuItem.SubmenuHeaderTemplateKey;
      
                menuItem.ApplyTemplate();  
            }  
            private void OnMenuItemClicked(object sender, RoutedEventArgs args)  
            {  
     
                RadRoutedEventArgs e = args as RadRoutedEventArgs;  
                RadMenuItem item = e.OriginalSource as RadMenuItem;  
     
                if (item.Header != null)  
                {  
                    if (item.Header.ToString() == "Copy")  
                    {  
                        RadMenuItem item3 = new RadMenuItem() { Header = "item1" };  
                        RadMenuItem item4 = new RadMenuItem() { Header = "item2" };  
                        item.Items.Add(item3);  
                        item.Items.Add(item4);  
     
                    }  
     
     
                }  
            }  
        }  
    }  
     

  8. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 25 May 2009 Link to this post

    Hi ruty,

    You can't attach a project to our forums, you should open a support ticket instead.

    As for the problem - due to a limitation I was unable to do it with the project I sent to you and by changing the template.  Therefore, I had to change the whole project. Now it is made with few bindings and custom classes. If you want to change the static items headers, change them in the Page.xaml. The dynamically generated items are set in the Page.xaml.cs .

    The project is a little complex, if you don't want the Contextmenu items to be generated on click, just to generate them at runtime we can provide a much simpler project.

    Hope this helps. If you need more help please let me know.

    Best wishes,
    Boyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 26 May 2009 Link to this post

    Hi,
    Thanks for the answer,
    Do  you will sent to me a general explication about  class's project???????

    additional, I try to set icons also to the other items(that their IsCustomizable="False")
    and the icon Does not seem.

    <local:MenuItem IsCustomizable="True" Header="Click me!"

    ImageSource="/ContextMenuDynamicaly;component/on.jpg" />

    <local:MenuItem Header="Static Item" ImageSource="/ContextMenuDynamicaly;component/on.jpg"/>

    <local:MenuItem Header="Static Item" ImageSource="/ContextMenuDynamicaly;component/on.jpg"/>

    <local:MenuItem Header="Static Item" ImageSource="/ContextMenuDynamicaly;component/on.jpg"/>

    If this is problem to set icon to the other items in this flow??
    (if I set to the other items IsCustomizable="True"  the icon apper, but I Do not want to set it.)

    additional,I want to create the conext menu and the items menu and all the objects(ItemTemplateSelector .....)  dinamicly
    can you sent me example to this in this project??
    Thanks .
  10. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 29 May 2009 Link to this post

    Hello ruty,

    Because of the requirement the custom context menu items to be expanded on click, we needed to add more code. If the items do not need to be created on click, the code in the project can be reduced by half or more.

    I attached an improved version of his project (contextmenudynamicaly-new.zip), as well as a version that demonstrates how to add custom items on mouse over, instead of click, which is much simpler (contextmenudynamicaly-no-click.zip). In both projects I use the latest service pack of RadControls we released a couple of days ago, hence the difference in attaching the menu item click handler. I strongly recommend using the ItemClick event on RadMenu and RadContextMenu instead of setting a routed event handler from code-behind.

    Regarding the more complex project. You want to have an item, that has no children, but with an expand arrow. Such item can be created with a DataTemplate, without hacks. A DataTemplate is applied on menu items only when they are databound, hence the additional code - we needed to create a ViewModel for the context menu, that represents its structure, and databind the menu to this model. The IsCustomizable property marks the items that should display the expand arrow and that need to be additionally processed. Those items have different DataTemplate, containing the arrow, than the regular items. Those two templates are applied through a DataTemplateSelector, which contains the logic that determines which template to be applied on which item. The rest is simple - the code-behind handles the menu click event and checks whether the user clicked on a "special" item. If a "special" item was clicked, it adds several subitems, according the business logic.

    There is one more thing that needs explanations: the telerik:ContainerBinding.ContainerBindings attached property. This attached property contains a collection of ContainerBinding objects, that specify bindings, that has to be applied on the RadMenuItem controls. This way we can bind the Icon property of RadMenuItem to the Icon property of our data items (MenuItem class).

    I hope this helps.

    All the best,
    Valeri Hristov
    Senior Developer, Telerik
    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  11. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 31 May 2009 Link to this post

    Hi,
    Thanks for the answer,
    I try it now.

     I want to set icons to all the items in the context menu,(not only the father item that from this sub context menu.) How????
    I write :

                MenuItem r = new MenuItem();  
                r.Header = "Click me!";  
                r.IsCustomizable = true;  
                r.ImageSource = new BitmapImage(new Uri("/ContextMenuDynamicaly;component/on.jpg", UriKind.Relative)); //"/ContextMenuDynamicaly;component/on.jpg";//new Image() { Source = new BitmapImage(new Uri("/ContextMenuDynamicaly;component/on.jpg", UriKind.Relative)) };  
                MenuItem t = new MenuItem();  
                t.Header = "Static Item";  
                t.ImageSource = new BitmapImage(new Uri("/ContextMenuDynamicaly;component/on.jpg", UriKind.Relative));  
     

    and only to the father item that from this sub context menu show icon.
    and to the anther items no show icons!!!

    additional, I want to create the context menu dinamicly,(not in xaml file)
    How I binding to the ItemsSource and to the ItemTemplateSelector????
    Thanks.

     

     

     

     

     

     

     

  12. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 01 Jun 2009 Link to this post

    Hi ruty,

    To bind the Icon property of the RadMenuItem controls we use ContainerBindings - you just need to create a new ContainerBindingCollection that contains the ContainerBinding for the Icon property and apply it on the DataTemplate with key "ItemTemplate". The "ArrowTemplate" template can be used as an example. When you have properly set the bindings, you need to set the ImageSource property of the MenuItem objects.

    Greetings,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  13. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 02 Jun 2009 Link to this post

    Thanks,
    But,  I want to set icons to all the items in the context menu,(not only the father item that from this sub context menu.) I write :
    MenuItem r = new MenuItem();  
                r.Header = "Click me!";  
                r.IsCustomizable = true;  
                r.ImageSource = new BitmapImage(new Uri("/ContextMenuDynamicaly;component/on.jpg", UriKind.Relative)); //"/ContextMenuDynamicaly;component/on.jpg";
    and this set icon in the item that contain subContextMenu.
    and when I write this also the another items(that they not contain subContextMenu ,IsCustomizable = false;)  
    the icon does not apper!!!!!!!!!!!!!!!!!!!
    Why????
    Can you help me pleease???????
    Thanks.
  14. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 02 Jun 2009 Link to this post

    Hi ruty,

    From my contextmenudynamicaly-new.zip example, change the following code:
    <telerik:HierarchicalDataTemplate x:Key="ItemTemplate" ItemsSource="{Binding Items}">
        <TextBlock HorizontalAlignment="Left" Text="{Binding Header}" />
    </telerik:HierarchicalDataTemplate>

    to:
    <telerik:HierarchicalDataTemplate x:Key="ItemTemplate" ItemsSource="{Binding Items}"
     telerik:ContainerBinding.ContainerBindings="{StaticResource ContainerBindings}">
        <TextBlock HorizontalAlignment="Left" Text="{Binding Header}" />
    </telerik:HierarchicalDataTemplate>

    And let me know how it goes.

    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  15. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 02 Jun 2009 Link to this post

    Hi,
    I write the code dinamicly in cs files instead of xaml files,
    I define in MenuModel class MenuItem objects (instead of in page.xaml) with the properties.
    and in Page.cs I define context menu and set his bindining to MenuModel.  
    MenuModel m=new MenuModel ();  
     ContextMenu.ItemsSource = m.Items;
    and I still have some problems:
    MenuModel class:
    public class MenuModel  
        {  
            public MenuModel()  
            {  
                MenuItem r = new MenuItem();  
                r.Header = "Click me!";  
                r.IsCustomizable = true;  
                r.ImageSource = new BitmapImage(new Uri("/ContextMenuDynamicaly;component/on.jpg", UriKind.Relative)); //"/ContextMenuDynamicaly;component/on.jpg";//new Image() { Source = new BitmapImage(new Uri("/ContextMenuDynamicaly;component/on.jpg", UriKind.Relative)) };  
                MenuItem t = new MenuItem();  
                t.Header = "Static Item";  
                t.ImageSource = new BitmapImage(new Uri("/ContextMenuDynamicaly;component/on.jpg", UriKind.Relative));  
                MenuItemCollection Collection = new MenuItemCollection();  
                Collection.Add(r);  
                Collection.Add(t);  
     
                this.Items = Collection;  
     
     
               
            }  
     
            public MenuItemCollection Items  
            {  
                get;  
                private set;  
            }  
        } 

    Page class:

    public partial class Page : UserControl  
        {  
            RadContextMenu ContextMenu;  
     
            public RadContextMenu ContextMenu1  
            {  
                get { return ContextMenu; }  
                set { ContextMenu = value; }  
            }  
     
             
             
            public Page()  
            {  
                InitializeComponent();  
                ContextMenu = new RadContextMenu();  
                ContextMenu.ItemClick+=new RadRoutedEventHandler(ContextMenu_ItemClick);  
                MenuModel m=new MenuModel ();  
                ContextMenu.ItemsSource = m.Items;  
                RadContextMenu.SetContextMenu(but, ContextMenu);  
            }  
     
            private void ContextMenu_ItemClick(object sender, RadRoutedEventArgs e)  
            {  
                MenuItem item = (e.OriginalSource as RadMenuItem).DataContext as MenuItem;  
     
                if (item != null)  
                {  
                    if (item.IsCustomizable)  
                    {  
                        // Clear the item image, because of a bug in the Silverlight runtime,  
                        // that prevents a content control from changing its content template  
                        // when it contains an image.  
                        ImageSource backup = item.ImageSource;  
                        item.ImageSource = null;  
     
                        item.Items.Add(new MenuItem() { Header = "Custom item 1" });  
                        item.Items.Add(new MenuItem() { Header = "Custom item 2" });  
                        item.Items.Add(new MenuItem() { Header = "Custom item 3" });  
     
                        // Reset the IsCustomizable flag to prevent the code from adding   
                        // the custom items again.  
                        item.IsCustomizable = false;  
     
                        // Restore the item image  
                        item.ImageSource = backup;  
                    }  
                }  
            }  
        } 


      Remainder of the class is unaltered.
     The result :
    the items in the context menu show on the context menu thus :
    instead of header it writes:
    "ContextMenuDinamicaly.MenuItem."
    and the icon does not appear at all.

    Can you help me with a sample of fully defining a context menu and item with sub menu items and icons while all of it runs from the code side??????
    Thanks.
  16. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 08 Jun 2009 Link to this post

    Hi

    In the last copule of days I was trying to do more researches with Telerik ContextMenu with no new approaches. It seems like the Context Menu does not fully support of:

    Creating the context menu dinamically with some sub menus
    Settings icons to some of the menu items

    If you do support it, can you please provide a code sample that demostrate it? (please try to do it all dinamically in the code)

    Thanks

    Ruty
  17. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 08 Jun 2009 Link to this post

    Hi ruty,

    I've attached an example demonstrating how to add data object from code behind and create RadContextMenu with bindable Header and Icon.

    Please let us know if this works for you.

    Kind regards,
    Hristo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  18. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 09 Jun 2009 Link to this post

    Hi

     

    I may was not clear… I need to create the whole context menu object (class) dynamically from the code. For example, when the user will press on a button the context menu object will be generated with its content. It had to contain some sub menus and I must be able to set icons for every item in the context menu (with or without sub menu).

     

    In your sample projects you always use the context menu from the XAML. It is created when the application runs and I need it to be created later on as the user do something. I cannot use is from the XAML and I need to create all of it from within the code (I will have to set its templates / styles from the code).

     

    Thanks,

     

  19. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 09 Jun 2009 Link to this post

    Hello ruty,

    It is even easier to create Context menu from code.
    Here is an example on how to do it:

    <UserControl x:Class="SilverlightApplication49.Page" 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300">  
     
        <Button Content="When clicked will create ContextMenu from Code" VerticalAlignment="Top" 
                Click="Button_Click" /> 
    </UserControl> 

    and code-behind:
    using System;  
    using System.Windows;  
    using System.Windows.Controls;  
    using System.Windows.Media.Imaging;  
    using Telerik.Windows.Controls;  
     
    namespace SilverlightApplication49  
    {  
        public partial class Page : UserControl  
        {  
            public Page()  
            {  
                InitializeComponent();  
            }  
     
            private void Button_Click(object sender, RoutedEventArgs e)  
            {  
                // Remove the button click handler so that you create ContextMenu once  
                Button btn = sender as Button;  
                btn.Click -= Button_Click;  
     
                // Create new RadContextMenu  
                RadContextMenu contextMenu = new RadContextMenu();  
     
                // Context menu will open on Button.Click event  
                contextMenu.EventName = "Click";  
     
                // Create some menu items with header and icon  
                RadMenuItem rootItem = CreateMenuItem("Item 1""Icons/Calendar.png");  
                RadMenuItem subItem1 = CreateMenuItem("Item 1""Icons/Carousel.png");  
                RadMenuItem subItem11 = CreateMenuItem("Item 1.1""Icons/Chart.png");  
                RadMenuItem subItem12 = CreateMenuItem("Item 1.2""Icons/ColorPicker.png");  
     
                // Add menu items to Items collection of menu item  
                subItem1.Items.Add(subItem11);  
                subItem1.Items.Add(subItem12);  
                rootItem.Items.Add(subItem1);  
     
                // Add the root menu item to Items collection of RadContextMenu  
                // Note that you could add more menu items  
                contextMenu.Items.Add(rootItem);  
     
                // Attach the context menu to the Button  
                RadContextMenu.SetContextMenu(btn, contextMenu);  
            }  
     
            // Helper method that creates RadMenuItem and set its header and icon properties  
            private static RadMenuItem CreateMenuItem(string header, string imageSource)  
            {  
                RadMenuItem subItem12 = new RadMenuItem()  
                {  
                    Header = header,  
                    Icon = new Image()  
                    {  
                        Source = new BitmapImage(new Uri(imageSource, UriKind.RelativeOrAbsolute))  
                    }  
                };  
                return subItem12;  
            }  
        }  

    You can change the CreateMenuItem method to stop creating Images for menu items if this is required.

    Let me know if this is your case.

    Best wishes,
    Hristo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  20. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 09 Jun 2009 Link to this post

    Hi,
    Thanks for your reply,
    I do it in my application .
    But my problem it :
    I create the sub context menu dinamicly, when the user press on the item in the context menu.
    but I want that on the item show arrow icon(in order to the user know that its have sub context menu).
    the defult in Telerik-the icon show only when have sub context menu. and in this correspondence ,you sent to me 
    some suggestion to solve it,but in one suggestion -it is impossible to set icons to the items,and in the second suggestion -the templets defined in the xaml file and not dinamicly.
    Now, I want to konw how I define the templetes (of the arrow icon and all the templets in your attach project:contextmenudynamicaly-new.zip) in the cs files.

    Thanks.
  21. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 11 Jun 2009 Link to this post

    Hello ruty,

    Why do you avoid XAML? Silverlight is designed to separate the visual interface from the business logic and if you try to mix those things, you will get a lot of obstacles, like the one that you cannot define a DataTemplate in code.

    The general idea of working with View Models is to define the UI controls, such as menus, buttons, text boxes, etc. in the XAML, define all DataTemplates in XAML and bind the UI controls to one or more View Models. Then in the code-behind you work only with the View Models - set properties, add items, etc. and the UI will respond to those changes. This pattern greatly simplifies the programming model and works in harmony with the Silverlight guidelines.

    Best wishes,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  22. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 14 Jun 2009 Link to this post

    Thanks,
    I use in XAML files in my application,
    but, this templet I need in cs file because the items dependent in the user and change in the run time.
    so, I can not to define it constant in the xaml file.

    If you will be able to even so to replay?????????
  23. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 15 Jun 2009 Link to this post

    Hi ruty,

    There are several ways to get the DataTemplate in code-behind:
    1) This one is the best in my opinion. Since most probably your DataTemplate will be one for each user, you could define it in the Application resources, in App.xaml:
    <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            x:Class="...">
        <Application.Resources>
      <DataTemplate x:Key="MenuItemTemplate">
       ...
      </DataTemplate>
        </Application.Resources>
    </Application>

    Which can be accessed in the code behind using the following code:
    DataTemplate menuItemTemplate = Application.Current.Resources["MenuItemTemplate"] as DataTemplate;

    2) The other way is to put the DataTemplate XAML represenatation in a string, then load it with XamlReader.Load()
    string menuItemTemplateXaml = "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"" +
    "xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" +
    "..." +
    "</DataTemplate>";

    DataTemplate menuItemTemplate = XamlReader.Load(menuItemTemplateXaml) as DataTemplate;

    Kind regards,

    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  24. ruty
    ruty avatar
    42 posts
    Member since:
    Mar 2009

    Posted 17 Jun 2009 Link to this post

    Hi,
    How I set in RadmenuItem delimiter between first RadmenuItem  to second RadmenuItem  ????????
    and in your application "contextmenudynamicaly.zip " - how I set delimiter  in menuItem ?????
    Thanks.
  25. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 17 Jun 2009 Link to this post

    Hello ruty,

    In the attached application:
    1) In the MenuItem.cs add a new IsSeparator property
    private bool isSeparator;
    public bool IsSeparator
    {
     get
     {
      return this.isSeparator;
     }
     set
     {
      if (this.isSeparator != value)
      {
       this.isSeparator = value;
       this.OnPropertyChanged("IsSeparator");
      }
     }
    }

    2) In Page.xaml add a ContainerBinding for the IsSeparator property:
    <telerik:ContainerBindingCollection x:Key="ContainerBindings">
        <telerik:ContainerBinding PropertyName="StaysOpenOnClick"
            Binding="{Binding IsCustomizable}" />
        <telerik:ContainerBinding PropertyName="Icon" Binding="{Binding Image}" />
        <telerik:ContainerBinding PropertyName="IsSeparator" Binding="{Binding IsSeparator}" />
    </telerik:ContainerBindingCollection>

    3) In Page.xaml update the ItemTemplate data template:
    <telerik:HierarchicalDataTemplate x:Key="ItemTemplate" ItemsSource="{Binding Items}"
        telerik:ContainerBinding.ContainerBindings="{StaticResource ContainerBindings}">
        <TextBlock HorizontalAlignment="Left" Text="{Binding Header}" />
    </telerik:HierarchicalDataTemplate>

    4) In MainPage.xaml.cs the MenuItem instances that should be separators should be added with IsSeparator = true;
    customizableItemData.Items.Add(new MenuItem()
    {
        IsSeparator = true
    });

    In case you are building a static RadMenu, you just need to set the IsSeparator property of RadMenuItem to true:
    <telerikNavigation:RadMenuItem IsSeparator="true" />

    Greetings,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
DevCraft banner