In Catel, there exists the IAuthenticationProvider class, which allows runtime authentication hooks to determine whether an ICommand can be executed or not. As of today, this IAuthenticationProvider has been extended with a new method called HasAccessToUIElement.
This method is used by the Authentication behavior, which can hide, collapse or disable UI elements based on the current user state. This is very handy when, for example, specific UI elements can only be accessed or edited by users in a specific role.
Creating a provider
It is important to create an authentication provider:
1: /// <summary>
2: /// Example implementation of the <see cref="AuthenticationProvider"/>. This class is not really implemented
3: /// like it should, because it shouldn't be this easy to set the current role. However, for the sake of simplicity,
4: /// this class has a simple property with the role of the user.
5: /// </summary>
6: public class AuthenticationProvider : IAuthenticationProvider
7: {
8: /// <summary>
9: /// Gets or sets the role the user is currently in.
10: /// </summary>
11: /// <value>The role.</value>
12: public string Role { get; set; }
13:
14: public bool CanCommandBeExecuted(ICatelCommand command, object commandParameter)
15: {
16: return true;
17: }
18:
19: public bool HasAccessToUIElement(FrameworkElement element, object tag, object authenticationTag)
20: {
21: var authenticationTagAsString = authenticationTag as string;
22: if (authenticationTagAsString != null)
23: {
24: if (string.Compare(authenticationTagAsString, Role, true) == 0)
25: {
26: return true;
27: }
28: }
29:
30: return false;
31: }
32: }
Registering the provider
The authentication provider must be registered in the ServiceLocator of Catel:
1: Catel.IoC.ServiceLocator.Instance.RegisterType<IAuthenticationProvider, AuthenticationProvider>();
Adding the behavior
Add the following namespaces to a xaml page:
1: xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
2: xmlns:catel="http://catel.codeplex.com"
Last but not least, it is time to add the behavior to a control. As you can see, it is possible to provide a custom AuthenticationTag, which is passed to the IAuthenticationProvider:
1: <TextBox>
2: <i:Interaction.Behaviors>
3: <catel:Authentication AuthenticationTag="Administrator" Action="Disable" />
4: </i:Interaction.Behaviors>
5: </TextBox>
Conclusion
Below are screenshots of the example applications (which can be found at http://catelexamples.codeplex.com or at the bottom of this post):
Logged in as administrator:

Logged in as read-only user:

Can I use this right away?
Yes! You can either download the demo application or the latest beta of Catel:
Do I need to use Catel all the way to use this behavior?
No, Catel is a toolkit, which means that you can use just the stuff you like. The only requirements are an implementation of the IAuthenticationProvider and it needs to be registered into the ServiceLocator (but no worries, the ServiceLocator supports MEF, Unity, Castle Windsor and Ninject).