c# - Xamarin.Forms DataTrigger not working -


i'm trying set datatrigger on control in xamarin.forms, cannot working.

i have property in viewmodel onpropertychange execution bool isvalid

i have tried:

datatrigger in xaml:

<customcontrols:numerictextbox     grid.row="0" grid.column="2"     text="{binding stringvalue, mode=twoway}"     isenabled="{binding iseditable}"     xalign="end">   <customcontrols:numerictextbox.style>     <style targettype="customcontrols:numerictextbox">       <style.triggers>         <datatrigger targettype="customcontrols:numerictextbox" binding="{binding isvalid}" value="true">           <setter property="textcolor" value="red"/>         </datatrigger>       </style.triggers>     </style>   </customcontrols:numerictextbox.style> </customcontrols:numerictextbox> 

getting exception: the property targettype required create xamarin.forms.datatrigger object.

datatrigger in control:

_item = new datatrigger(typeof(numerictextbox)); _item.binding = new binding("isvalid",bindingmode.default,new negativebooleanconverter()); _item.value = true; setter s = new setter(); s.property = textcolorproperty; s.value = color.red; _item.setters.add(s); this.style.triggers.add(_item); 

exception: exception has been thrown target of invocation.

i have tried changing line : this.style.triggers.add(_item); this.triggers.add(_item);. wasn't raising exception, didn't worked.

in last try, hits converter, not change textcolor of control.

am doing wrong? how handle that?

i ran same issue. workaround, instead of using datatrigger bind textcolor property color property in viewmodel. in isvalid setter set color based on value.

public bool isvalid {     { return _isvalid; }     set     {         _isvalid = value;         mynewtextcolorproperty = _isvalid ? color.blue : color.red;          onpropertychanged();     } } 

Comments