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

RadConextMenu "Opening" command doesn't get executed for the first time

4 Answers 143 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Tayyaba
Top achievements
Rank 1
Tayyaba asked on 10 Jul 2017, 09:04 AM
I am hooking up "Opening" event of RadContextMenu to load the menuItems dynamically on tree nodes based on the type of node. But it doesn't work for the first right click, rather it loads the menuItems correctly afterwards based on the type of tree node on which this menu is being loaded.

4 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 13 Jul 2017, 08:49 AM
Hello Tayyaba,

I tested this out with the RadContextMenu for RadGridView demo from the SDK Samples Browser and the Opening event is fired as expected at my end.

Can you test this out with this project and the other available ones under the ContextMenu category and let me know if you manage to reproduce the same behavior? If that is not the case, please share some more details on your exact setup so that I can suggest a viable solution based on your requirements.

I'm looking forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Tayyaba
Top achievements
Rank 1
answered on 08 Aug 2017, 05:58 AM

Hi,

Sample project is uploaded here:
https://www.dropbox.com/s/43ueokgj0581pic/TelerikNavigation.zip?dl=0

Because i wasn't being able to  upload the project here.

In this project you'll see that the context menu doesn't gets loaded with the respective items for the first time only, afterwards it works fine.

Kindly let me know how can I fix this issue.

 

Thanks.

0
Accepted
Dilyan Traykov
Telerik team
answered on 09 Aug 2017, 12:29 PM
Hello Tayyaba,

It seems that interaction triggers cannot be easily applied inside of a style as suggested in this thread.

Instead, you can use the EventToCommandBehavior class to bind your custom command to the Opening event of the RadContextMenu.

<Style x:Key="ContextMenuStyle" TargetType="{x:Type telerik:RadTreeViewItem}">
    <Setter Property="telerik:RadContextMenu.ContextMenu">
        <Setter.Value>
            <telerik:RadContextMenu InheritDataContext="False" DataContext="{Binding UIElement.ParentTreeView.DataContext, RelativeSource={RelativeSource Self}}"
                                    ItemsSource="{Binding ContextMenu.MenuItems}"
                ItemContainerStyle="{StaticResource MenuItemContainer}">
                <telerik:EventToCommandBehavior.EventBindings>
                    <telerik:EventBinding EventName="Opening" Command="{Binding ContextMenuOpeningCommand}" CommandParameter="{Binding Path=UIElement.Item, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:RadContextMenu}}" />
                </telerik:EventToCommandBehavior.EventBindings>
            </telerik:RadContextMenu>
        </Setter.Value>
    </Setter>
</Style>

This solves the aforementioned issue at my end. Could you please try this at your end as well and let me know if it works for you?

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Tayyaba
Top achievements
Rank 1
answered on 10 Aug 2017, 04:19 AM

It works!

Thank you Dilyan.

Tags
ContextMenu
Asked by
Tayyaba
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Tayyaba
Top achievements
Rank 1
Share this question
or