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

6 posts, 0 answers
  1. John
    John avatar
    7 posts
    Member since:
    Nov 2010

    Posted 04 Mar Link to this post

    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

  2. Nasko
    Admin
    Nasko avatar
    685 posts

    Posted 08 Mar Link to this post

    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.
  3. John
    John avatar
    7 posts
    Member since:
    Nov 2010

    Posted 10 Mar in reply to Nasko Link to this post

    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
  4. Nasko
    Admin
    Nasko avatar
    685 posts

    Posted 10 Mar Link to this post

    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.
  5. John
    John avatar
    7 posts
    Member since:
    Nov 2010

    Posted 10 Mar in reply to John Link to this post

    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

  6. Nasko
    Admin
    Nasko avatar
    685 posts

    Posted 14 Mar Link to this post

    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.
Back to Top