Cannot get Text of ContextMenu

1 posts, 0 answers
  1. Hamid
    Hamid avatar
    4 posts
    Member since:
    Mar 2012

    Posted 05 Mar 2012 Link to this post

    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

Back to Top