c# - Styling a WPF Passwordbox -


i'm trying following: if no password entered text "password" should shown.

but template no password shown, , if i'm using decorator or scrollviewer can't change color of text.

do have ideas achieve this?

here's styling code:

<style targettype="{x:type passwordbox}" x:key="password">         <setter property="template">             <setter.value>                 <controltemplate targettype="passwordbox">                     <grid>                         <passwordbox background="{staticresource brushdark}" foreground="{staticresource brushtextnormal}" borderbrush="{staticresource brushborderinput}" borderthickness="1"/>                         <textblock horizontalalignment="left"                             verticalalignment="center"                             text="password"                             margin="5,0,5,0"                             foreground="#ff808080"                             ishittestvisible="false"                             x:name="usermessage"                             visibility="hidden"/>                         <!--<scrollviewer foreground="{staticresource brushtextnormal}" background="{staticresource brushtextnormal}" x:name="part_contenthost"/>-->                         <!--<decorator textblock.foreground="white" x:name="part_contenthost"/>-->                     </grid>                     <controltemplate.triggers>                         <multitrigger>                             <multitrigger.conditions>                                 <condition property="tag" value=""/>                                 <condition property="iskeyboardfocuswithin" value="false"/>                             </multitrigger.conditions>                             <setter property="visibility" targetname="usermessage" value="visible"/>                         </multitrigger>                     </controltemplate.triggers>                 </controltemplate>             </setter.value>         </setter>     </style> 

if create custom controltemplate passwordbox or textbox need put scrollviewer named x:name="part_contenthost instead of inner passwordbox

from passwordbox syles , templates

part_contenthost - visual element can contain frameworkelement. text of passwordbox displayed in element.

and change foreground setter in style. also, side node, same background , use templatebinding in controltemplate. give more flexibility , allow change background and/or foreground manually without changing controltemplate

<style targettype="{x:type passwordbox}" x:key="password">    <setter property="foreground" value="{staticresource brushtextnormal}" />    <setter property="background" value="{staticresource brushdark}"/>    <setter property="template">       <setter.value>          <controltemplate targettype="{x:type passwordbox}">             <grid background="{templatebinding background}">                <scrollviewer x:name="part_contenthost" .../>                <textblock .../>                            </grid>             <controltemplate.triggers>                <!-- removed -->             </controltemplate.triggers>          </controltemplate>       </setter.value>    </setter> </style> 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -