getting reference to context menu

5 posts, 1 answers
  1. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 06 Jan 2012 Link to this post

    how can i get a reference to a context menu created in xaml for a gridview like so.

    <RadGridView IsReadOnly="True" AutoGenerateColumns="False" x:Name="gridDispatch" >
        <telerik:RadContextMenu.ContextMenu >
            <telerik:RadContextMenu  x:Name="coco1"  >
                <telerik:RadContextMenu.Items>
                    <telerik:RadMenuItem  Header="Copy"   >
                        <telerik:RadMenuItem.Icon>
                            <Image Source="/Images/copy.png"     />
                        </telerik:RadMenuItem.Icon>
                    </telerik:RadMenuItem>
                </telerik:RadContextMenu.Items>
            </telerik:RadContextMenu>
        </telerik:RadContextMenu.ContextMenu>
        <telerik:RadGridView.Columns>
        </telerik:RadGridView.Columns>
    </RadGridView>

    i would like as the grid is created to add some default menu items but i need to get a reference to the xaml contentmenu to add the items.

    thanks
    dco
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 06 Jan 2012 Link to this post

    Hello David ,

    Keeping references to visual elements in virtualized items control is dangerous. I would strongly recommend the following alternative :

    Expose your items as a static resource. Then in the template for the context menu  bind the to these items , instead of setting them in code.

    Let me know in case you need additional assistance on that.
    Kind regards,
    Pavel Pavlov
    the Telerik team

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

  3. DevCraft banner
  4. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 06 Jan 2012 Link to this post

    Pavel,

    let me get more general about what i am trying to do.
    maybe you can suggest a better way for what i am trying to do

    i have inherited the radgridview and have added a default context menu that holds things like
    "copy","export" , etc.

    Now when i use that inherited radgridview i may want to add some more menu items specific to that implementation
    like "delete this row","recalc something or other". typically i place these idems in xaml.

    So now i need to merge the implementation specific menu with the default menu.

    So i thought if i can get a reference to the implementation specific menu
    i can add the default menu items.

    any ideas would be appreciated

    thanks
    dco
  5. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 06 Jan 2012 Link to this post

    Hi David ,

    How about handling the loaded event of an element defined in the template of the context menu ?
    Inside the event handler you can do your additional initialization  ? And of course there you can easily get a reference to the context menu.

    Regards,
    Pavel Pavlov
    the Telerik team

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

  6. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 06 Jan 2012 Link to this post

    that would work

    i was trying though to handle it from the inherited base grid definition/code side.
    without wiring the "implementation specific" grid to an event

    but what you are saying would work
    i could add a default event that handles the load of the menu and merge it there. 

    thanks pavel
    dco
Back to Top
DevCraft banner