xaml - PasswordBox Hint Text in WPF -
i wrote passwordbox style.i want hint text in passwordbox when lost focus ,the hint text appering.where i'm doing mistake, how can solve problem?
here code:
<style targettype="{x:type passwordbox}" xmlns:sys="clr-namespace:system;assembly=mscorlib"> <style.resources> <visualbrush x:key="bg1" alignmentx="center" alignmenty="center" stretch="none" > <visualbrush.visual> <label content="enter password" foreground="lightgray" margin="5,0,0,0"/> </visualbrush.visual> </visualbrush> <visualbrush x:key="bg2" alignmentx="center" alignmenty="center" stretch="none" > <visualbrush.visual> <label content="" foreground="lightgray" margin="5,0,0,0"/> </visualbrush.visual> </visualbrush> </style.resources> <setter property="fontsize" value="16"/> <setter property="foreground" value="#ff585858"/> <setter property="verticalcontentalignment" value="center"/> <setter property="horizontalcontentalignment" value="center"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type passwordbox}"> <border cornerradius="2" x:name="border" background="{templatebinding background}" borderthickness="1" borderbrush="lightgray"> <scrollviewer scrollviewer.verticalscrollbarvisibility="visible" margin="0" scrollviewer.cancontentscroll="true" x:name="part_contenthost"/> </border> <controltemplate.triggers> <trigger property="isfocused" value="true"> <setter property="borderbrush" targetname="border" value="#ffd0d0d0"/> <setter property="borderthickness" targetname="border" value="2"/> </trigger> <datatrigger binding="{binding path=password}" value="{x:static sys:string.empty}"> <setter property="background" value="{staticresource bg2}" /> </datatrigger> <datatrigger binding="{binding path=password}" value="{x:null}"> <setter property="background" value="{staticresource bg1}" /> </datatrigger> <trigger property="iskeyboardfocused" value="true"> <setter property="background" value="white" /> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> </style>
thanks advice.
password property in passwordbox not dependency property security reasons. cannot used in trigger. triggers applied password property not working. reason, hint text appearing if have valid text in it. trigger applied on iskeyboardfocused working, regardless of whether password empty or null.
the following post must giving idea implement watermark password box,
http://prabu-guru.blogspot.in/2010/06/how-to-add-watermark-text-to-textbox.html
Comments
Post a Comment