c# - DataTrigger on each item's textbox in ItemsControl -


i have itemscontrol displays list of labels & textboxes used data input , button executes command when pressed (using input values):

<datatemplate x:key="stringparametertemplate">     <stackpanel name="stackpanel_parameter"                 orientation="horizontal">         <label name="parameterlabel"                content="{binding parameterlabel}"                horizontalcontentalignment="right"                width="200" />         <textbox name="parametertextblock"                  text="{binding parametervalue, updatesourcetrigger=propertychanged}"                  width="300"/>     </stackpanel> </datatemplate>          . . .          <!-- display parameters -->         <itemscontrol name="listview_parameters"                       itemssource="{binding parametercollection, notifyonsourceupdated=true, updatesourcetrigger=propertychanged}"                       itemtemplateselector="{staticresource taskparametertemplateselector}"                       borderthickness="0" />  <button name="executetaskbutton"         content="{binding buttonlabel}"         style="{staticresource executebuttonstyle}"         command="executetask"> 

i create style enables/disables button when of parameters listview_parameters empty. this:

<!-- execute button enable / disable --> <style x:key="executebuttonstyle" targettype="{x:type button}">     <setter property="button.isenabled" value="true" />     <style.triggers>         <datatrigger binding="{binding elementname=listview_parameters, path=parametervalue}" value="">             <setter property="isenabled" value="false" />         </datatrigger>         </style.triggers> </style> 

you can achieve single binding using converter.

<button content="{binding buttonlabel}"         isenabled="{binding path=itemssource,                              relativesource={relativesource ancestortype={x:type itemscontrol}},                              converter={local:itemstobooleanconverter}}" /> 

then converter takes input of itemssource (for example list of objects) - , can return true if fields want have values, false otherwise.

the converter boilerplate, this:

public class itemstobooleanconverter : markupextension, ivalueconverter 

... important part like this, if using list:

public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         var items = value ilist<parameterlist>;         return !(items.any( <you check here empty values> );     } 

you'll need sure parameter entry fields bound sources converter check current.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -