I have a WPF application. I have different users of this application and each user has a different level associated with them. People with higher level dont have access to some menu items.
Is there a way to switch between the menu items? Is toggling the individual menu item’s visibility an efficient way to accomplish this? Is there any other way for this?
You could achieve this using bindings and converters. Basically if you have a property on the
DataContextof the menu (which will be inherited by the menu items) that specifies the level of permissions; then you could bind that to the visibility of the menu items.Obviously, because the permissions would not be implicitly convertible to the
Visibilityenum, you would have to create an implementation of theIValueConverterinterface, which would be specific to converting permissions to visibilities, and vice versa, based on the current permissions level. This would also require the converter having some concept of the current permissions level, so either you would want to give it access to some static property (which I would not advise), or you would need to gain hold of the converter instance (making sure you only use one instance) and pass the current permissions level to it.