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

ContextMenu.ItemClick event and Tag issue

4 Answers 125 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Brian Mains
Top achievements
Rank 1
Brian Mains asked on 29 Mar 2010, 08:38 PM
Hello,

I'm programmably creating menu items within the context menu.  I assign one a Tag property, but the MenuItem in the event argument that comes back in the ItemClick event has a null Tag, so I'm not sure why that is the case?  The tag is set in the collection of items in the menu....

Thanks.

4 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 30 Mar 2010, 08:12 AM
Hi Brian Mains,

We are unable to reproduce this issue.
Could you send us sample project that reproduce it?

Greetings,
Hristo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brian Mains
Top achievements
Rank 1
answered on 01 Apr 2010, 09:52 AM
Hey,

I have a RadGrid, which defines a context menu:

<

 

tel:RadGridView x:Name="DataViewer" AutoGenerateColumns="True"

 

 

 

 

 

 

IsFilteringAllowed="True" VerticalContentAlignment="Stretch">

 

 

 

 

<nav:RadContextMenu.ContextMenu>

 

<

 

nav:RadContextMenu Opened="RadContextMenu_Opened" ItemClick="RadContextMenu_ItemClick">

 

</

 

nav:RadContextMenu>

 

 

 

 

 

 

 

 

</nav:RadContextMenu.ContextMenu>

 

 

 

 

 

 

 

 

</tel:RadGridView>

 

 


I programmably create the UI like:

private

 

void ShowSingleHeaderColumnContextMenu(RadContextMenu menu)

 

{

menu.Items.Clear();

menu.Items.Add(

 

new MenuItem { Header = "A" Tag = new ATask() });

 

menu.Items.Add(

 

new MenuItem { Header = "B", Tag = new BTask() });

 

}

 


I do see these iems in the list.  And I expect that when I process the item click, the tag would be there, but this is null:

private

 

void RadContextMenu_ItemClick(object sender, RadRoutedEventArgs e)

 

{

 

 

RadContextMenu menu = e.Source as RadContextMenu;

 

 

 

RadMenuItem clickedItem = e.OriginalSource as RadMenuItem;

 

 

 

BaseTask task = clickedItem.Tag as BaseTask;  //common base class

 

 

 

if (task == null)

 

 

 

return;

 

 


This is always true; it's always null...  but the item in the list is not.

Also, I notice that the context menu doesn't go away; do I have to manually close it?

Thanks.

 

 

 

0
Accepted
Hristo
Telerik team
answered on 01 Apr 2010, 11:50 AM
Hello Brian Mains,

You are adding MenuItem (which is Microsoft control). Instead you should add RadMenuItems to get the desired behavior (Tag not null and Close context menu on ItemClick).

Let us know if you need more help.

Greetings,
Hristo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brian Mains
Top achievements
Rank 1
answered on 03 Apr 2010, 02:38 PM
Doh.  Thanks.
Tags
ContextMenu
Asked by
Brian Mains
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Brian Mains
Top achievements
Rank 1
Share this question
or