<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyWPFCustomControls" > <Style TargetType="{x:Type local:WaterMarkTextBox}">
<Setter Property="Background" Value="#ffffff"/>
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#5d7fad"></Setter>
<Setter Property="FontWeight" Value="Normal"></Setter>
<Setter Property="Foreground" Value="#0c223a"></Setter>
<Setter Property="Padding" Value="5,0,5,2"></Setter>
<Setter Property="Margin" Value=""/>
<Setter Property="FontSize" Value=""></Setter>
<Setter Property="FontFamily" Value="Arial"></Setter>
<Setter Property="FlowDirection" Value="LeftToRight"></Setter>
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:WaterMarkTextBox}" >
<Border Background="{TemplateBinding Background}" x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="">
<Grid> <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<ContentPresenter x:Name="PART_WatermarkHost" Content="{TemplateBinding Watermark}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Margin="{TemplateBinding Padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding}" Foreground="Gray" Focusable="False"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
</Grid> </Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsFocused" Value="False"/>
<Condition Property="Text" Value=""/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" TargetName="PART_WatermarkHost" Value="Visible"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsFocused" Value="True" >
<Setter TargetName="Bd" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="" BlurRadius="" Color="#fe1C67C7"></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="" BlurRadius="" Color="#Fe9DBADF"></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="Height" Value="Auto">
<Setter Property="MinHeight" Value=""/>
</Trigger>
<Trigger Property="Validation.HasError" Value="True">
<Setter TargetName="Bd" Property="BorderBrush" Value="Red"/>
<Setter Property="ToolTip">
<Setter.Value>
<Binding
Path="(Validation.Errors).CurrentItem.ErrorContent"
RelativeSource="{x:Static RelativeSource.Self}"
/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="">
<!--<Setter.Value>
<Thickness Bottom="" Left="" Right="" Top=""></Thickness>
</Setter.Value>-->
</Setter>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers> <!--<Trigger Property="Attach:AttachProperty.IsMandatory" Value="True">
<Setter Property="Background" Value="LightYellow"/>
</Trigger>-->
<!--<Trigger Property="IsFocused" Value="True" >
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="" BlurRadius="" Color="#fe1C67C7"></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Button.Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="" BlurRadius="" Color="#Fe9DBADF"></DropShadowEffect>
</Setter.Value>
</Setter>
</Trigger>-->
<!--<Trigger Property="Validation.HasError" Value="True"> <Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value=""/>
<Setter Property="ForceCursor" Value="False"/>
<Setter Property="Foreground" Value="Gray"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="5,0,5,2"></Setter>
<Setter Property="Margin" Value=""/>
<Setter Property="MinHeight" Value=""/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border Background="#ffffff" BorderBrush="Red" x:Name="Bd" CornerRadius="" BorderThickness="">
<Grid>
<TextBlock x:Name="PART_MyWaterMarkTextBlock" Visibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Left" Padding="5,0,0,3" Foreground="Gray"/>
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</Border> </ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>-->
</Style.Triggers>
</Style> </ResourceDictionary>

xaml

 public  class WaterMarkTextBox:TextBox
{ public string Watermark
{
get { return (string)GetValue(WatermarkProperty); }
set { SetValue(WatermarkProperty, value); }
} // Using a DependencyProperty as the backing store for Watermark. This enables animation, styling, binding, etc...
public static readonly DependencyProperty WatermarkProperty =
DependencyProperty.Register("Watermark", typeof(string), typeof(WaterMarkTextBox), new PropertyMetadata(null)); public WaterMarkTextBox()
{ }
}

cs

waterMarkTextBox的更多相关文章

  1. WPF 水印TextBox WatermarkTextBox

    //https://blog.csdn.net/puchitomato/article/details/12248691 转自以上链接,自己添加了Enter响应事件.    public class ...

  2. 【转】WPF TextBox和PasswordBox加水印

    Textbox加水印 Textbox加水印,需要一个VisualBrush和触发器验证Text是否为空,在空的时候设置背景的Brush就可以实现水印效果. <TextBox Name=" ...

  3. windows phone 水印TextBox

    原文来自:wp教程网 原理:在失去焦点和获取焦点的时候,判断Text值是否为空或者是否与水印值相同,然后修改TextBox中的Text和Foreground. 代码如下: /* =========== ...

  4. Silverlight behavior(行为) trigger 大全

    behavior是超级有用的东西,一定要学会,因为这个就是面向对象编程中的封装.超级重要! 欢迎大家如果有好的效果,可以给我留言,我打算不断的整理这个behavior,希望不久用behavior可以做 ...

  5. WinForm程序中的类TextBox的自定义控件, 添加失去焦点的功能

    原理: 一.在控件的后台代码中, 添加布尔类型的属性CanFocus 二.在控件的构造函数中, 注册Enter事件的处理方法. 并在处理方法中,根据CanFocus属性的值来决定是否可以丢失焦点, 如 ...

  6. WPF实现TextBox水印效果

    在日常项目中,一个TextBox需要输入用户名,我们通常的做法是先用一个TextBlock来说明,例如下面的截图: 今天将使用另外一种方式来展示,使用水印的方式.请参考下面的代码: <Windo ...

  7. Asp.net 上传图片添加半透明图片或者文字水印的方法

    主要用到System.Drawing 命名空间下的相关类,如Brush.Image.Bitmap.Graphics等等类 Image类可以从图片文件创建Image的实例,Bitmap可以从文件也可以从 ...

  8. C# WinForm TextBox添加水印效果

    1.新建项目添加WatermarkTextBox类: using System; using System.Collections.Generic; using System.Text; using ...

  9. WinRT Toolkit 介绍--Control篇

    WinRT toolkit是组针对Windows Runtime XAML开发的一系列Control,extension和helper类.它和Windows Phone Toolkit一样,也是由很多 ...

随机推荐

  1. Linux安装字体

    用惯了Win7的字体,感觉雅黑看着很舒服,就动手在Linux安装下,简单描述下: 第一步:百度一下,找到微软雅黑字体(.ttf)下载 第二步:把下载的字体放到cd /usr/share/fonts/z ...

  2. pip 安装命令

    pip官网文档 https://pip.pypa.io/en/latest/reference/pip.html 若没有将c:\Python27\Scripts加入到path环境变量,可以在c:\Py ...

  3. linux /usr/bin/ld cannot find 解决

    问题: 在linux环境编译应用程式或lib的source code时常常会出现如下的错误讯息: /usr/bin/ld: cannot find -lxxx 这些讯息会随着编译不同类型的source ...

  4. c#缓存 笔记

    1:缓存. 你需要了解大数据高并发的瓶颈在哪里,一般都是数据库层面的,机械硬盘承载不起非常快速的读写操作,cpu承载不起大量的逻辑运算,所以最基本的解决思路就是:1.换固态硬盘加快硬盘的读写效率.2. ...

  5. 阿里2014校招笔试题(南大)——利用thread和sleep生成字符串的伪随机序列

    引言:题目具体描述记不大清了,大概是:Linux平台,利用线程调度的随机性和sleep的不准确性,生成一个各位均不相同的字符数组的伪随机序列.不得使用任何库函数.(这句记得清楚,当时在想线程库算不算, ...

  6. cmd命令查看局域网内计算机信息

    ping [计算机名] ping -a [IP] nbtstat -a [IP] net view arp -a nslookup www.baidu.com 查看当前dns地址 tracert [I ...

  7. pair<>结构体模版的用法

    1.pair算是一个结构体模版,定义的时候是这样的: pair<T1,T2> P; 其中T1,T2可以是int,string,double,甚至是vector<>. 2.进行初 ...

  8. JAVA addShutdownHook测试

    public static void main(String[] args) { System.out.println("1111111111"); try { Thread.sl ...

  9. apache ab下载测试

    http://httpd.apache.org/docs/2.0/programs/ab.html-->http://httpd.apache.org/docs/current/platform ...

  10. chaper3_exerise_Uva1368_DNA序列

    #include<iostream> #include<stdio.h> #include<cmath> #include<string> #inclu ...