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一样,也是由很多 ...
随机推荐
- oracle/node-oracledb 数据库驱动 与 Meteor 驱动包!
oracle/node-oracledb: https://github.com/oracle/node-oracledb Oracle 官方维护. metstrike/meteor-oracle ...
- 【leetcode】Wildcard Matching
Wildcard Matching Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any ...
- poj 1611(并查集)
http://poj.org/problem?id=1611 题意:有个学生感染病毒了,只要是和这个学生接触过的人都会感染,而和这些被感染者接触的人,也会被感染,现在给定你一些协会的人数,以及所在学生 ...
- Java web 开发环境搭建
1.下载jdk-8u60-windows-i586.exe;安装过程会让指定jre的安装路径,此处最好指定和jdk安装一个目录下(D:\Program Files\Java\jdk1.8.0_60,D ...
- Greedy:The Water Bowls(POJ 3185)
水池 题目大意:给定一个20的数组,全都是0和1,可以翻一个数改变成另一个数(0或者1),但是其左右两边的数都会跟着变为原来的相反数,问你怎么用最小的操作数使全部数变成0 这一题的:满足 1:翻转次序 ...
- 【leetcode】Swap Nodes in Pairs (middle)
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- Ubuntu(Linux)使用Eclipse搭建C/C++编译环境
转自:http://www.cppblog.com/kangnixi/archive/2010/02/10/107636.html 首先是安装Eclipse,方法有两种: 第一种是通过Ub ...
- iOS 访问粘贴板
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = self.label.text;
- Git - 使用指南
GIT (分布式版本控制系统) 编辑 Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.[1] Git的读音为/gɪt/. Git是一个开源的分布式版本控制系统,可以 ...
- tengine-2.1.0 源码安装
[root@localhost tengine-]# yum update -y [root@localhost tengine-]# yum install gcc gcc-c++ autoconf ...