RadMenuItem Click Event

5 posts, 2 answers
  1. Naseem
    Naseem avatar
    70 posts
    Member since:
    Nov 2010

    Posted 27 Apr 2012 Link to this post

    Hi,

    I need to generate RadMenuItems dynamically at runtime. here is my code:

                     Telerik.Windows.Controls.RadMenuItem newItem;
                Telerik.Windows.Controls.RadMenuItem newSubItem;
      
                foreach (var item in lstResult)
                {
                    newItem = new Telerik.Windows.Controls.RadMenuItem() { Header = item.Title, IconTemplate = (System.Windows.DataTemplate)this.Resources["IconTemplateBestMatches"], Tag = item.Code };
                      
                    newSubItem = new Telerik.Windows.Controls.RadMenuItem() { Header = "Create Similar", IconTemplate = (System.Windows.DataTemplate)this.Resources["IconTemplateCreateSimilar"], Tag = item.Code };
                    newSubItem.Click += new Telerik.Windows.RadRoutedEventHandler(newSubItemCreateSimilar_Click);
                    newItem.Items.Add(newSubItem);
      
                    newItem.Click += new Telerik.Windows.RadRoutedEventHandler(newItem_Click);
                      
                    selItem.Items.Add(newItem);
                }

    My issue is with the Click event , when ever I click any newSubItem , first of all the  "newSubItemCreateSimilar_Click" fires and then "newItem_Click" fires as well which is really strange!  I need it to call just "newSubItemCreateSimilar_Click" .

    Is there anything I'm doing wrong????

    I'd be thankful if you assist me on this,

    Many thanks,
    Naseem



  2. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 27 Apr 2012 Link to this post

    Hi Naseem,

    You just need to add e.Handled = true; in the subitem click event handler to prevent this behavior:

    void newSubItemCreateSimilar_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        e.Handled = true;
    }


    All the best,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Naseem
    Naseem avatar
    70 posts
    Member since:
    Nov 2010

    Posted 29 Apr 2012 Link to this post

    Hi Yana,

    Thank you so much. Your solution fixed the issue. Now when ever I click on newSubItem , it just raise the 'newSubItemCreateSimilar_Click' .

    However I have realized when I click on newItem , the 'newItem_Click' won't fire!
    I'd be grateful if you could asist me on it,

    Many thanks Yana,

    Kind Regards,
    Naseem
  5. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 01 May 2012 Link to this post

    Hi Naseem,

    You just need to set NotifyOnHeaderClick property of the RadMenu to true:

    <telerik:RadMenu  NotifyOnHeaderClick="True" />

    All the best,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Naseem
    Naseem avatar
    70 posts
    Member since:
    Nov 2010

    Posted 02 May 2012 Link to this post

    Many thanks Yana,
    You fixed my issue :)

    Kind Regards,
    Naseem
Back to Top
DevCraft banner