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

How do I hide/show WPF RadMenuItems using MVVM implementation?

5 Answers 306 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 04 Mar 2017, 03:53 PM

I'm using the Telerik CUSTOM_MVVM_WPF example to build out a series of menus using
MVVM and RadMenuItems.

I would like to add the ability to hide/show menu items to the MVVM model.

How do I extend the sample to implement this functionality?

 

Thanks,

JohnB

5 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 08 Mar 2017, 10:44 AM
Hi John,

From the provided description it seems you are referring to the Customization_MVVV example from our SDK Repository. If that is the case in order to achieve the desired functionality you need to add an aditional property of type bool inside the MenuItemViewModel. Using it you could be able to easily toggle the Visibility of the MenuItems by binding it to the Visibility property and using the built-in BooleanToVisibilityConverter.

We have modified the sample in order to demonstrate you that approach - notice how some of the items are not visible after the added boolean property is set to False.

Hope this helps.

Regards,
Nasko
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.
0
John
Top achievements
Rank 1
answered on 10 Mar 2017, 06:08 AM
Nasko:  Is there an issue with the zipped project, or am I missing something.
The archive seems to be empty of .cs and .xaml files.

Thanks,
JB
0
Nasko
Telerik team
answered on 10 Mar 2017, 11:44 AM
Hi John,

We have checked the attached zip file and it seems the archive could be unzipped as expected - there are no missing files. Could you please, provide some additional information about the issues you are having with the attached file? If you prefer some specific format instead of .zip, please let us know and we will try to attach the project with the desired format.

Regards,
Nasko
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.
0
John
Top achievements
Rank 1
answered on 10 Mar 2017, 04:49 PM

Hi:

This example works great. Thx!

How do I extend it to set the visibility dynamically in c# code behind.

For instance, I would like to set visibility of some menu items in response to a command.

Thanks,

JohnB

0
Nasko
Telerik team
answered on 14 Mar 2017, 07:26 AM
Hello John,

You could pass as CommandParameter the  "MenuItemsSource" of the Menu and inside the command to find the desired MenuItem whose visibility you like to change. The IsVisible property is bound to the Visibility property of the RadMenuItem and changing its value will change the Visibility as well.

We have modified your sample with the described above approach - please, notice how the visibility of a specific item changes when the Button that is added to project gets pressed.

We hope this will help you.

Regards,
Nasko
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.
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Nasko
Telerik team
John
Top achievements
Rank 1
Share this question
or