Show UI element based on authentication

8 Jan

Often it’s necessary to show or hide UI elements based on the users authentication. This short post will show a way to use an application context to work as source.

The application context is a class I have placed in the root of my project. It contain a static property called Current used to gain easy access to it’s properties. It implements INotifyPropertyChanged so it’s possible to notify if a property is changed. In this sample I have added a bool property called IsAuthenticated.

2011-01-08_000958

To actually use the application context in bindings in the xaml it’s necessary to point to a resource that points to the class. In the sample below I have called the namespace root and called the resource Context. Furthermore I have added a resource to a bool to visibility converter from the Quebec framework and called it BoolToVisibilityConverter.

2011-01-08_001236

Now it’s possible to use the IsAuthenticated property from the application context to show or hide an UI element.

2011-01-08_001515

You can download the complete sample here.

by xamlgeek 
@thomasmartinsen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: