c# - Using enum in ConverterParameter -
i building application can used many users. each user classified 1 of next authentication levels:
public enum authenticationenum { user, technitian, administrator, developer }
some controls (such buttons) exposed levels of users. have property holds authentication level of current user:
public authenticationenum currentauthenticationlevel { get; set; }
i want bind property 'visibilty' property of controls , pass parameter converter method, telling lowest authentication level able see control. example:
<button visibility="{binding path=currentauthenticationlevel, converter={staticresource authenticationtovisibility}, converterparameter="administrator"}"/>
means 'administrator' , 'developer' can see button. unfortunately, above code passes "administrator" string. of course can user switch-case inside converter method , convert string authenticationenum. ugly , prone maintenance errors (each time enum changes - converter method should change).
is there better way pass not trivial object parameter?
arsenmkrt's answer correct,
another way of doing use x:static syntax in converterparameter
<button ... visibility="{binding path=currentauthenticationlevel, converter={staticresource authenticationtovisibility}, converterparameter={x:static local:authenticationenum.administrator}}"/>
and in converter
public class authenticationtovisibility : ivalueconverter { public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { authenticationenum authenticationenum = (authenticationenum)parameter; //... } }
Comments
Post a Comment