In my WPF client Application I use GenericIdentity for security:
GenericIdentity MyIdentity = new GenericIdentity("Identity");
String[] MyStringArray = { "Admin", "Editor" };
GenericPrincipal MyPrincipal = new GenericPrincipal(MyIdentity, MyStringArray);
Now I want to show/hide WPF objects according to user role.
Iv’e tried several methods such as:
Visibility="{Binding Source=Thread.CurrentPrincipal, Converter={StaticResource RoleToVisibilityConverter}, ConverterParameter=Administrator}"
which make the ‘value’ object in the converter a String of “Thread.CurrentPrincipal”, also tried:
Visibility="{Binding Path=Thread.CurrentPrincipal, Converter={StaticResource RoleToVisibilityConverter}, ConverterParameter=Administrator}"
And
Visibility="{Binding Source=Thread.CurrentPrincipal, Path=CurrentPrincipal, Converter={StaticResource RoleToVisibilityConverter}, ConverterParameter=Administrator}"
which skip the converter entirely.
This is my first C#/.net program so I don’t really have a lot of knowledge in the area, Would greatly appreciate a solution. thanks!
First, to access static properties, you need to use the
x:Staticmarkup extension:This assumes you have
on the root element of your XAML.
Second, you don’t show how you set the principal, but you have to do it using
AppDomain.SetThreadPrincipal().Third, you set the role to
Admin, but then check forAdministrator.