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

how to disable RadContextMenu RadMenuItems at runtime MVVM

2 Answers 397 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Randy Hompesch
Top achievements
Rank 1
Randy Hompesch asked on 07 Feb 2017, 02:17 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 09 Feb 2017, 10:28 AM
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Randy Hompesch
Top achievements
Rank 1
answered on 13 Feb 2017, 01:28 PM

Thanks so much!

 

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