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

RadMenuItem Click Event

4 Answers 155 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Naseem
Top achievements
Rank 1
Naseem asked on 27 Apr 2012, 05:44 AM
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



4 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 27 Apr 2012, 12:47 PM
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 >>

0
Naseem
Top achievements
Rank 1
answered on 30 Apr 2012, 01:44 AM
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
0
Accepted
Yana
Telerik team
answered on 01 May 2012, 12:41 PM
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 >>

0
Naseem
Top achievements
Rank 1
answered on 02 May 2012, 07:07 AM
Many thanks Yana,
You fixed my issue :)

Kind Regards,
Naseem
Tags
Menu
Asked by
Naseem
Top achievements
Rank 1
Answers by
Yana
Telerik team
Naseem
Top achievements
Rank 1
Share this question
or