xaml - How to set textbox background transferent when readonly = true in windows phone 8 -
i want set textbox background tranfernt when readonly = true don't want default color .. can give me solution
i trying 1 not working
<textbox name="mytextbox" background="transparent" text="my text" isreadonly="true" /> thanks
setting isreadonly on textbox applies styles textbox including background. can change these styles doing following:
- open xaml file in blend within visual studio
- in blend, right click on textbox , click on edit template-->edit copy
- in next dialog, tick application define new style in app.xaml , give style name.
- click save , close blend.
you see new style created in app.xaml. want change value of background story board target property under readonly visual state whichever color want.
to apply new style textbox add style="{staticresource textboxstyle1}" textbox textboxstyle1 name assigned style.
edit:
here full style, add in app.xaml inside <application.resources>
<style x:key="textboxstyle1" targettype="textbox"> <setter property="fontfamily" value="{staticresource phonefontfamilynormal}"/> <setter property="fontsize" value="{staticresource phonefontsizemediumlarge}"/> <setter property="background" value="{staticresource phonetextboxbrush}"/> <setter property="foreground" value="{staticresource phonetextboxforegroundbrush}"/> <setter property="borderbrush" value="{staticresource phonetextboxbrush}"/> <setter property="selectionbackground" value="{staticresource phoneaccentbrush}"/> <setter property="selectionforeground" value="{staticresource phonetextboxselectionforegroundbrush}"/> <setter property="borderthickness" value="{staticresource phoneborderthickness}"/> <setter property="padding" value="2"/> <setter property="template"> <setter.value> <controltemplate targettype="textbox"> <grid background="transparent"> <visualstatemanager.visualstategroups> <visualstategroup x:name="commonstates"> <visualstate x:name="normal"/> <visualstate x:name="mouseover"/> <visualstate x:name="disabled"> <storyboard> <objectanimationusingkeyframes storyboard.targetproperty="background" storyboard.targetname="mainborder"> <discreteobjectkeyframe keytime="0" value="transparent"/> </objectanimationusingkeyframes> <objectanimationusingkeyframes storyboard.targetproperty="borderbrush" storyboard.targetname="mainborder"> <discreteobjectkeyframe keytime="0" value="{staticresource phonedisabledbrush}"/> </objectanimationusingkeyframes> <objectanimationusingkeyframes storyboard.targetproperty="foreground" storyboard.targetname="contentelement"> <discreteobjectkeyframe keytime="0" value="{staticresource phonedisabledbrush}"/> </objectanimationusingkeyframes> </storyboard> </visualstate> <visualstate x:name="readonly"> <storyboard> <objectanimationusingkeyframes storyboard.targetproperty="visibility" storyboard.targetname="mainborder"> <discreteobjectkeyframe keytime="0"> <discreteobjectkeyframe.value> <visibility>collapsed</visibility> </discreteobjectkeyframe.value> </discreteobjectkeyframe> </objectanimationusingkeyframes> <objectanimationusingkeyframes storyboard.targetproperty="visibility" storyboard.targetname="readonlyborder"> <discreteobjectkeyframe keytime="0"> <discreteobjectkeyframe.value> <visibility>visible</visibility> </discreteobjectkeyframe.value> </discreteobjectkeyframe> </objectanimationusingkeyframes> <objectanimationusingkeyframes storyboard.targetproperty="background" storyboard.targetname="readonlyborder"> <discreteobjectkeyframe keytime="0" value="red"/> </objectanimationusingkeyframes> <objectanimationusingkeyframes storyboard.targetproperty="borderbrush" storyboard.targetname="readonlyborder"> <discreteobjectkeyframe keytime="0" value="{staticresource phonetextboxbrush}"/> </objectanimationusingkeyframes> <objectanimationusingkeyframes storyboard.targetproperty="foreground" storyboard.targetname="contentelement"> <discreteobjectkeyframe keytime="0" value="{staticresource phonetextboxreadonlybrush}"/> </objectanimationusingkeyframes> </storyboard> </visualstate> </visualstategroup> <visualstategroup x:name="focusstates"> <visualstate x:name="focused"> <storyboard> <objectanimationusingkeyframes storyboard.targetproperty="background" storyboard.targetname="mainborder"> <discreteobjectkeyframe keytime="0" value="{staticresource phonetextboxeditbackgroundbrush}"/> </objectanimationusingkeyframes> <objectanimationusingkeyframes storyboard.targetproperty="borderbrush" storyboard.targetname="mainborder"> <discreteobjectkeyframe keytime="0" value="{staticresource phonetextboxeditborderbrush}"/> </objectanimationusingkeyframes> </storyboard> </visualstate> <visualstate x:name="unfocused"/> </visualstategroup> </visualstatemanager.visualstategroups> <border x:name="mainborder" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" margin="{staticresource phonetouchtargetoverhang}"/> <border x:name="readonlyborder" borderbrush="{staticresource phonedisabledbrush}" borderthickness="{templatebinding borderthickness}" background="transparent" margin="{staticresource phonetouchtargetoverhang}" visibility="collapsed"/> <border borderbrush="transparent" borderthickness="{templatebinding borderthickness}" background="transparent" margin="{staticresource phonetouchtargetoverhang}"> <contentcontrol x:name="contentelement" borderthickness="0" horizontalcontentalignment="stretch" margin="{staticresource phonetextboxinnermargin}" padding="{templatebinding padding}" verticalcontentalignment="stretch"/> </border> </grid> </controltemplate> </setter.value> </setter> </style> then in text box point style:
<textbox isreadonly="true" style="{staticresource textboxstyle1}" />
Comments
Post a Comment