WPF adds a watermark to the PasswordBox control, the lowest-level version

Source: Internet
Author: User
Tags visibility

The reason is also very direct, the boss need, a start for the TextBox worry, find this control make use of, as to copyright, internal tools also do not sell, and I do not understand English, also ignored:

Extended WPF toolkit™community EditionOthers are professional, so I do not study the technical aspects, but the password box can not add watermarks, which is quite boring. Really lazy to engage in the control, wrote a style to do with: hint watermark is to write dead, after all, is the original control, do not make the use of, see not the past to write a control it.
1     <Stylex:key= "PasswordBoxStyle1"TargetType="{x:type PasswordBox}">2         <Setter Property= "BorderThickness"Value= "1"/>3         <Setter Property= "Padding"Value= "2"/>4         <Setter Property= "Template">5             <Setter.value>6                 <ControlTemplateTargetType="{x:type PasswordBox}">7                    <Borderx:name= "Bd"Snapstodevicepixels= "true"borderthickness="{TemplateBinding BorderThickness}"Background="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}">8                         <GridMargin="{TemplateBinding Padding}">9                             <ScrollViewerx:name= "PART_ContentHost"Snapstodevicepixels="{TemplateBinding Snapstodevicepixels}" />Ten                             <TextBlockx:name= "Water"HorizontalAlignment= "Left"VerticalAlignment= "Center"Foreground= "Lightgray"FontSize="{TemplateBinding FontSize}" One Text= "Please enter password"Visibility= "Hidden"/> A                         </Grid> -                     </Border> -                      the                     <controltemplate.triggers> -                         <Trigger Property= "IsEnabled"Value= "false"> -                             <Setter Property= "Background"TargetName= "Bd"Value="{dynamicresource {x:static Systemcolors.controlbrushkey}}"/> -                             <Setter Property= "Foreground"Value="{dynamicresource {x:static Systemcolors.graytextbrushkey}}"/> +                         </Trigger> -                         <MultiTrigger> +                             <multitrigger.conditions> A                                 <Condition Property= "IsFocused"Value= "false"/> at                                 <Condition Property= "Extentwidth"Value= "0"SourceName= "PART_ContentHost"/> -                             </multitrigger.conditions> -                             <Setter Property= "Visibility"Value= "Visible"TargetName= "Water"/> -                         </MultiTrigger> -                     </controltemplate.triggers> -                 </ControlTemplate> in             </Setter.value> -         </Setter>         to     </Style>
PasswordBoxStyle1

WPF adds a watermark to the PasswordBox control, the lowest-level version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.