how to disable RadContextMenu RadMenuItems at runtime MVVM

3 posts, 1 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    70 posts
    Member since:
    Nov 2008

    Posted 07 Feb Link to this post

    Hi,

    I have a treeview that uses the datatemplate shown below. It has a context menu. I'd like to be able to disable or hide certain items depending on which node in the tree they click on. Is this possible? If so, can someone share some example code of how to do this in an MVVM fashion?

    Thanks ... Ed

     

     

    <HierarchicalDataTemplate DataType ="{x:Type vm:AttachmentContainer}"  ItemsSource="{Binding Children}">
        <TextBlock Text="{Binding Name}" >
               <telerik:RadContextMenu.ContextMenu>
                    <telerik:RadContextMenu  Opened="tv_ContextMenuOpened" >
                        <telerik:RadMenuItem x:Name="icon" Header="Upload File"   >
                            <telerik:RadMenuItem.Icon><Image Source="/Images/Upload.png"/></telerik:RadMenuItem.Icon>
                        </telerik:RadMenuItem>
                         <telerik:RadMenuItem Header="New Folder" >
                            <telerik:RadMenuItem.Icon>
                                <Image Source="/Images/NewFolder.png"/>
                            </telerik:RadMenuItem.Icon>
                         </telerik:RadMenuItem>
                         <telerik:RadMenuItem Header="Delete Folder" >
                            <telerik:RadMenuItem.Icon>
                                <Image Source="/Images/DeleteSmall.png"/>
                            </telerik:RadMenuItem.Icon>
                         </telerik:RadMenuItem>                               
                    </telerik:RadContextMenu>
                </telerik:RadContextMenu.ContextMenu>
        </TextBlock>
    </HierarchicalDataTemplate>
  2. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    545 posts

    Posted 09 Feb Link to this post

    Hello Ed,

    Could you please have a look at the Custom Context Menu demo from the WPF Controls Samples as I believe it demonstrates a behavior similar to the one you're looking for?

    You can introduce a new IsEnabled property to the SolutionItem class and use that in the PreapreContextOperationsForItem method and contextMenuItemStyle to have certain items disabled in a given context.

    Do let me know if you need any help in implementing this.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    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. Randy Hompesch
    Randy Hompesch avatar
    70 posts
    Member since:
    Nov 2008

    Posted 13 Feb in reply to Dilyan Traykov Link to this post

    Thanks so much!

     

Back to Top