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

getting reference to context menu

4 Answers 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 06 Jan 2012, 12:38 PM
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

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 06 Jan 2012, 12:47 PM
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 >>

0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 06 Jan 2012, 01:06 PM
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
0
Accepted
Pavel Pavlov
Telerik team
answered on 06 Jan 2012, 01:11 PM
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 >>

0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 06 Jan 2012, 01:26 PM
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
Tags
GridView
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Pavel Pavlov
Telerik team
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or