c# - Binding a buttons IsEnabled/Visibility properties using its x:Name as a parameter in a method in the code-behind -


i need pass in controls name method in security object returns boolean value isenabled property , method returns visibility(collapsed, hidden, or visible). these both have checked permission purposes.

i have tried using objectdataprovider examples show user input textbox parameters. need pass control name method based off button's x:name property.

what simplest , efficient way of handling problem. in advance.

update: trying use converter , convert method came with:

    public object convert(object[] values, type targettype, object parameter, system.globalization.cultureinfo culture)     {         if (values != null)         {             datatable tblpermissions = (datatable)values[0];             string sfunctionname = values[1].tostring();              datarow[] rows = tblpermissions.select("fun_name = '" + sfunctionname + "'");             if ((bool)rows[0]["fun_enable"])                 return true;             else                 return false;         }          return string.empty;     } 

the following xaml:

                    <button.isenabled>                         <multibinding converter="{staticresource isfunctionenabledconverter}">                             <binding elementname="{staticresource permissionstable}" />                             <binding elementname="btnsave" path="name" />                         </multibinding>                     </button.isenabled> 

you can write ivalueconverter make method call , pass in control using {binding relativesource={relativesource self}, converter={staticresource myconverter}}. in convert method can cast value control , access control's name property pass security method. checking targettype can determine whether output boolean (for isenabled) or visibility enum.

***update

i assume "permissiontable" resource used converter binding datatable you're trying use string identify element name binding source. try using source="{staticresource permissionstable}" instead pass datatable resource itself.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -