I am trying to figure out how to show/hide a navigation link based on the users role. Currently I am testing to see if the user is logged in, and that works great – here’s my code:
<HyperlinkButton x:Name="AdminLinkButton" Visibility="{Binding User.IsAuthenticated, Source={StaticResource WebContext}, TargetNullValue=false, Converter={StaticResource VisibilityConverter}}" Style="{StaticResource LinkStyle}" NavigateUri="/Admin" TargetName="ContentFrame" Content="{Binding Path=Strings.AdminPageTitle, Source={StaticResource ApplicationResources}}"/>
However, now I need to change it to make sure the Admin button is only visible if the user is in the “Admin” role.
Anybody have a suggestion?
Thanks,
One option is to pass a parameter via the ConverterParameter which will identify the type of user associated with determining the result returned from the converter.
Another option to avoid the String limitation imposed by the
ConverterParamteris to store the type of user logged in via a Singleton or other static means which the converter can query to know what user is logged in and thus return the resulting visibility. If you must access the data within XAML you can do so by making use ofx:Static.