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

5 posts, 1 answers
  1. Tayyaba
    Tayyaba avatar
    12 posts
    Member since:
    Apr 2017

    Posted 10 Jul Link to this post

    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.
  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 13 Jul Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Tayyaba
    Tayyaba avatar
    12 posts
    Member since:
    Apr 2017

    Posted 08 Aug in reply to Dilyan Traykov Link to this post

    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.

  4. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 09 Aug Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Tayyaba
    Tayyaba avatar
    12 posts
    Member since:
    Apr 2017

    Posted 09 Aug in reply to Dilyan Traykov Link to this post

    It works!

    Thank you Dilyan.

Back to Top