silverlight - Apply style to Windows Phone TextBox when it doesn't contain text -
silverlight - Apply style to Windows Phone TextBox when it doesn't contain text -
i'm trying find out way apply style textbox element when not contain text. want textbox have different background color (for instance) when or not contain text.
as triggers not can utilize in silverlight (afaik), there way this? preferrably without writing custom implementation of textbox behavior. thanks.
i ended using default behavior (conditionbehavior):
<i:interaction.triggers> <i:eventtrigger eventname="textchanged"> <i:interaction.behaviors> <ec:conditionbehavior> <ec:conditionalexpression> <ec:comparisoncondition leftoperand="{binding text, elementname=textbox}" rightoperand="" operator="notequal"/> </ec:conditionalexpression> </ec:conditionbehavior> </i:interaction.behaviors> <ec:changepropertyaction propertyname="background" value="{staticresource phonetextboxbrush}" /> </i:eventtrigger> <i:eventtrigger eventname="textchanged"> <i:interaction.behaviors> <ec:conditionbehavior> <ec:conditionalexpression> <ec:comparisoncondition leftoperand="{binding text, elementname=textbox}" rightoperand="" operator="equal"/> </ec:conditionalexpression> </ec:conditionbehavior> </i:interaction.behaviors> <ec:changepropertyaction propertyname="background" value="transparent" /> </i:eventtrigger> </i:interaction.triggers>
this should easy accomplish custom behavior. utilize this link create behavior can attached textbox control. in onattached
method, can handle textchanged
event of lostfocus
method check whether textbox empty or not. accordingly, can switch style between styles.
p.s: might need phone call textbox.applytemplate() method after changing style. note sure though.
silverlight windows-phone-7
Comments
Post a Comment