zoukankan      html  css  js  c++  java
  • WPF 为 PasswordBox 控件添加水印,最低级版

    原因也很直接,老板需要,一开始为TextBox发愁,就找了这个控件凑合用,至于版权什么的,内部工具也不卖钱,而且我不懂英文,也就无视了:

     
    人家是专业的,所以技术方面我就不研究了,但是,密码框却不能加水印,这倒是挺无聊的。
    实在懒得搞控件,就自己写了个样式凑合着用:
    提示水印是写死的,毕竟是原生控件,不会搞的就凑合用,看不过去就自己写一个控件吧。
     1     <Style x: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                 <ControlTemplate TargetType="{x:Type PasswordBox}">
     7                    <Border x:Name="Bd" SnapsToDevicePixels="true" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
     8                         <Grid Margin="{TemplateBinding Padding}">
     9                             <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
    10                             <TextBlock x:Name="water" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="LightGray" FontSize="{TemplateBinding FontSize}"
    11                                        Text="请输入密码" Visibility="Hidden"/>
    12                         </Grid>
    13                     </Border>
    14                     
    15                     <ControlTemplate.Triggers>
    16                         <Trigger Property="IsEnabled" Value="false">
    17                             <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    18                             <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    19                         </Trigger>
    20                         <MultiTrigger>
    21                             <MultiTrigger.Conditions>
    22                                 <Condition Property="IsFocused" Value="false"/>
    23                                 <Condition Property="ExtentWidth" Value="0" SourceName="PART_ContentHost"/>
    24                             </MultiTrigger.Conditions>
    25                             <Setter Property="Visibility" Value="Visible" TargetName="water"/>
    26                         </MultiTrigger>
    27                     </ControlTemplate.Triggers>
    28                 </ControlTemplate>
    29             </Setter.Value>
    30         </Setter>        
    31     </Style>
    PasswordBoxStyle1
  • 相关阅读:
    Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy
    Twsited异步网络框架
    MySQL-python模块
    python3安装Fabric模块
    PInvoke.net Visual Studio Extension
    资源下载站
    WPF RTSP存储到一个文件中的位置
    Windows 7 中未能从程序集System.ServiceModel
    无法在WEB服务器上启动调试,Web 服务器配置不正确
    CS0016: 未能写入输出文件“c:WINDOWSMicrosoft.NETFramework.。。”--“拒绝访问
  • 原文地址:https://www.cnblogs.com/3Tai/p/3956505.html
Copyright © 2011-2022 走看看