Tag Archives: authentication

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