waterMarkTextBox
<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的更多相关文章
- WPF 水印TextBox WatermarkTextBox
//https://blog.csdn.net/puchitomato/article/details/12248691 转自以上链接,自己添加了Enter响应事件. public class ...
- 【转】WPF TextBox和PasswordBox加水印
Textbox加水印 Textbox加水印,需要一个VisualBrush和触发器验证Text是否为空,在空的时候设置背景的Brush就可以实现水印效果. <TextBox Name=" ...
- windows phone 水印TextBox
原文来自:wp教程网 原理:在失去焦点和获取焦点的时候,判断Text值是否为空或者是否与水印值相同,然后修改TextBox中的Text和Foreground. 代码如下: /* =========== ...
- Silverlight behavior(行为) trigger 大全
behavior是超级有用的东西,一定要学会,因为这个就是面向对象编程中的封装.超级重要! 欢迎大家如果有好的效果,可以给我留言,我打算不断的整理这个behavior,希望不久用behavior可以做 ...
- WinForm程序中的类TextBox的自定义控件, 添加失去焦点的功能
原理: 一.在控件的后台代码中, 添加布尔类型的属性CanFocus 二.在控件的构造函数中, 注册Enter事件的处理方法. 并在处理方法中,根据CanFocus属性的值来决定是否可以丢失焦点, 如 ...
- WPF实现TextBox水印效果
在日常项目中,一个TextBox需要输入用户名,我们通常的做法是先用一个TextBlock来说明,例如下面的截图: 今天将使用另外一种方式来展示,使用水印的方式.请参考下面的代码: <Windo ...
- Asp.net 上传图片添加半透明图片或者文字水印的方法
主要用到System.Drawing 命名空间下的相关类,如Brush.Image.Bitmap.Graphics等等类 Image类可以从图片文件创建Image的实例,Bitmap可以从文件也可以从 ...
- C# WinForm TextBox添加水印效果
1.新建项目添加WatermarkTextBox类: using System; using System.Collections.Generic; using System.Text; using ...
- WinRT Toolkit 介绍--Control篇
WinRT toolkit是组针对Windows Runtime XAML开发的一系列Control,extension和helper类.它和Windows Phone Toolkit一样,也是由很多 ...
随机推荐
- zju3547
题意:给出n(1<=n<=10^8),求小于n的,求所有与n互质的数字的四次幂的加和是多少. 分析:容斥原理 首先要知道四次幂求和公式,1^4+2^4+...+n^4=n*(n+1)*(2 ...
- WebRequest 获取网页乱码
问题:在用WebRequest获取网页源码时得到的源码是乱码. 原因:1,编码不对 解决办法:设置对应编码 WebRequest request = WebRequest.Create(Url);We ...
- java 入门 第二季1
(1). 类和对象(java 语言是面向对象的) 1). 类是对象的类型 具有相同的属性和方法的一组对象的集合 类:属性和方法 定义类: 类名 属性 方法 //class为关键字 2.定义类时,首字母 ...
- Effective C++ -----条款17:以独立语句将newed对象置入智能指针
以独立语句将newed对象存储于(置入)智能指针内.如果不这样做,一旦异常被抛出,有可能导致难以察觉的资源泄露.
- 【el表达式】jsp中设置默认图像
<img alt="头像" src="${empty members.headPic ?'images/icon.png':members.headPic}&quo ...
- 3ds max输出图片
通过渲染菜单调出改窗口,然后调整成这种模式,就能渲染出这种效果的图. 可以调背景色: 全局照明:染色,这个控制的是渲染物体的颜色
- 营业额统计(bzoj1588)
Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每 ...
- db2 Hidden columns
When a table column is defined with the implicitly hidden attribute, that column is unavailable unle ...
- NYOJ题目1048破门锁
- python中读取\写入CSV中数据的方法