<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. poj 2403

    http://poj.org/problem?id=2403 题意:就是给你m个单词,以及n段对话.每一个单词都有所对应的价值.求对话中的价值总和 题解:很简单,就是用单词和价值对应起来,然后再寻找就 ...

  2. winserver2008 Oracle 11g 安装

    .在Windows Server2008R2上安装Oracle Database 11g Release 2,下载64位的安装程序,地址: 文件1:http://download.oracle.com ...

  3. cpu中断

    中断是什么?cpu在中断的时候做了些什么? 答:中断就是中止当前正在执行的工作,而去执行引起中断的事件,当引起中断的事件执行完毕之后,CPU继续执行以前的未执行完的工作. CPU暂时中断当前正在执行的 ...

  4. tomcat有哪些性能调优方法

    前几天看见一篇介绍性能调优文章,觉得不错.特此收藏(http://blog.csdn.net/lifetragedy/article/details/7708724)

  5. javascript开发 ios和android app的简单介绍

    先看几个名词解释: nodejs ionic,Cordova,phoneGap,anjularjs react-native,reactjs nodeJs 的介绍参见这里,写的很好http://www ...

  6. cannot use the same dataset for report.dataset and page.dataset

    把page中的dataset中填的数据表删除.(改成not assigned)

  7. Java for LeetCode 224 Basic Calculator

    Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...

  8. [Android]检查当前手机是否有网络

    // Check network connection private boolean isNetworkConnected(){ ConnectivityManager connectivityMa ...

  9. Mathematics:Semi-prime H-numbers(POJ 3292)

      Semi-prime H-numbers 题目大意,令4n+1的数叫H数,H数素数x的定义是只能被x=1*h(h是H数),其他都叫合数,特别的,当一个数只能被两个H素数乘积得到时,叫H-semi数 ...

  10. Android RadioButton selector背景

    RadioButton selector 背景 <?xml version="1.0" encoding="utf-8"?> <selecto ...