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

Cannot get Text of ContextMenu

0 Answers 34 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Hamid
Top achievements
Rank 1
Hamid asked on 06 Mar 2012, 12:06 AM

I am trying to implement a ContextMenu for a treeview control (WPF) by using your Telerik's online tutorial. However, I often get error message as I copy & paste the tutorial code.

Here is what I have in XAML:
        <telerik:RadTreeView Canvas.Left="18" Canvas.Top="136" Height="615" Name="raceTreeView" Width="311" Background="Bisque" IsLineEnabled="True">
            <!-- This code segement implements a popup menu on the treeview.-->
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu ItemClick="TreeContextMenu_ItemClick">
                    <telerik:RadMenuItem Header="Add" />
                    <telerik:RadMenuItem Header="Delete" />
                    <telerik:RadMenuItem Header="Edit" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
        </telerik:RadTreeView>

Here is the relevant segements in C# code-behind:
using Telerik.Windows;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;

....

private void TreeContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
   {
    MenuItem item = (e.OriginalSource as RadMenuItem).DataContext as MenuItem;
    switch ( item.Text )
    {
        case "Add":
            ....
        case "Edit":
            ....
        case "Delete":
            ....
        }
     }
   }

I get an error message on this line : switch ( item.Text )
'System.Windows.Controls.MenuItem' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Windows.Controls.MenuItem' could be found (are you missing a using directive or an assembly reference?)

How can I solve this problem?

Thanks,
Hamid

Please disregard this post. I found the error.
Thanks,
Hamid

No answers yet. Maybe you can help?

Tags
ContextMenu
Asked by
Hamid
Top achievements
Rank 1
Share this question
or