<Window x:Class="BindingExam.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:BindingExam"
        Title="MainWindow" Height="413.027" Width="488.793" FontSize="16">
    <Window.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter  Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel LastChildFill="True">
                            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="14" FontWeight="Bold"
                                       ToolTip="{Binding ElementName=PlaceHolder,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">*</TextBlock>
                            <Border BorderBrush="Green" BorderThickness="1">
                                <AdornedElementPlaceholder Name="PlaceHolder"></AdornedElementPlaceholder>
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                    
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}">
                        
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition  Height="2*"></RowDefinition>
        </Grid.RowDefinitions>
        <ListBox Margin="3" Name="lstProducts" DisplayMemberPath="ModelName" VirtualizingPanel.CacheLength="3"></ListBox>
        <StackPanel Margin="3" Grid.Row="1" Orientation="Horizontal">
            <Button Margin="3" Grid.Row="1" Name="btnGetProducts" Click="btnGetProducts_Click_1">GetProducts</Button>
            <Button Margin="3" Grid.Row="1" Name="btnDelete" Click="btnDelete_Click_1">Delete</Button>
            <Label VerticalAlignment="Center">UnitCost></Label>
            <TextBox Width="200" Name="txtMinUnitCost">0</TextBox>
        </StackPanel>
        
        <Grid Grid.Row="2" Name="gridProduct" DataContext="{Binding ElementName=lstProducts, Path=SelectedItem}" Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
               
            </Grid.ColumnDefinitions>
            <Label Margin="3">Model Number:</Label> 
            <TextBox Name="txtModelNumber" Margin="3" Grid.Column="1" Text="{Binding Path=ModelNumber, Mode=OneWay}" Grid.ColumnSpan="2"></TextBox>
            <Label Margin="3" Grid.Row="1">Model Name:</Label>
            <TextBox Name="txtModelName" Margin="3" Grid.Column="1" Grid.Row="1" Text="{Binding Path=ModelName, Mode=OneWay}" Grid.ColumnSpan="2"></TextBox>
            <Label Margin="3" Grid.Row="2">Unit Cost:</Label>
            <TextBox Name="txtUnitCost" Margin="3" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Validation.Error="txtUnitCost_Error_1">
                <TextBox.Text>
                    <Binding Path="UnitCost" NotifyOnValidationError="True">
                        <Binding.ValidationRules>
                            <!--<ExceptionValidationRule></ExceptionValidationRule>-->
                            <!--<DataErrorValidationRule></DataErrorValidationRule>-->
                            <local:PositivePriceRule Min="0" Max="1000"></local:PositivePriceRule>
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox.Text>
            </TextBox>
            <Label Margin="3" Grid.Row="3">Description:</Label>
            <TextBox Name="txtDescription" Margin="3" Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3" Text="{Binding Path=Description, Mode=OneWay}"
                     TextWrapping="Wrap"></TextBox>
        </Grid>
    </Grid>
</Window>

WPF 验证错误模板的更多相关文章

  1. 理解和使用WPF 验证机制(值得推荐)

    首先建立一个demo用以学习和实验WPF Data Validation机制.创建一个数据实体类: public class Employee { public string Name { get;  ...

  2. 理解和使用WPF 验证机制

    博客 学院 下载 更多 写博客 发布Chat 登录注册 理解和使用WPF 验证机制 原创 2013年06月20日 11:15:37 7404 首先建立一个demo用以学习和实验WPF Data Val ...

  3. WPF 详解模板

    在WPF中有三大模板 ControlTemplate,ItemsPanelTemplate,DataTemplate.其中ControlTemplate和 ItemsPanelTemplate是控件模 ...

  4. 远程连接身份验证错误,又找不到加密Oracle修正

    远程连接服务器出现了错误,错误信息为:远程连接身份验证错误,又找不到加密Oracle修正. 服务器系统:Windows Server2016 客户端系统:Windows10家庭版和专业版   出错原因 ...

  5. 20180726 - Windows 10 Pro 下远程桌面连接提示“出现身份验证错误”

    问题:Windows 10 Pro 下远程桌面连接提示“出现身份验证错误” [Window Title]远程桌面连接 [Content]出现身份验证错误.要求的函数不受支持 远程计算机: 192.16 ...

  6. mstsc远程连接发生身份验证错误要求的函数不受支持

    在win7电脑上使用远程连接连接一台服务器时,出现发生身份验证错误要求的函数不受支持的错误,原因是本地组策略配置错误,如下图: 解决办法: 进入windows命令行模式输入命令: 会弹出本地策略组编辑 ...

  7. win7 远程连接服务器出现身份验证错误,又找不到加密Oracle修正

    今天想用远程桌面连接登录服务器,结果,弹出一个错误的提示框:发生身份验证错误,要求的函数不受支持. 然后在网上找了相关的教程,基本上所有的方法都是如下所示: 策略路径:"计算机配置" ...

  8. WIN7远程桌面连接--“发生身份验证错误。要求的函数不受支持”

    故障现象:WIN7发现远程桌面无法连接了,报“发生身份验证错误.要求的函数不受支持”的错误: 解决办法:开始菜单->运行gpedit.msc 打开配置项:计算机配置>管理模板>系统& ...

  9. Win10远程桌面 出现 身份验证错误,要求的函数不受支持,这可能是由于CredSSP加密Oracle修正 解决方法

    升级至win10 最新版本18362,远程桌面连接Window Server时报错信息如下: 出现身份验证错误,要求的函数不正确,这可能是由于CredSSP加密Oracle修正. 解决方法: 运行 g ...

随机推荐

  1. Annotation研究的一些学习资料

    转自chanyinhelv原文Annotation研究的一些学习资料 下面是我最近对Annotation研究的一些学习资料,收集于此,供大家学习之用. 一.Annotation要素类介绍 在GeoDa ...

  2. [Now] Configure secrets and environment variables with Zeit’s Now

    Often your project will require some secret keys or tokens - for instance, API keys or database auth ...

  3. JNI_Android 项目中调用.so动态库实现详解

    转自:http://www.yxkfw.com/?p=7223 1. 在Eclipse中创建项目:TestJNI 2. 新创建一个class:TestJNI.java package com.wwj. ...

  4. 【u020】Couple number

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 任何一个整数N都能表示成另外两个整数a和b的平方差吗?如果能,那么这个数N就叫做Couple numb ...

  5. Android 设置图片 Bitmap任意透明度

    两种思路,第一种思路是通过对Bitmap进行操作,将Bitmap的像素值get到一个int[]数组里,因为在android里Bitmap通常是ARGB8888格式,所以最高位就是A通道的值,对齐进行改 ...

  6. Linux下iptables屏蔽IP和端口号

    http://blog.csdn.net/kobejayandy/article/details/24332597 iptables 屏蔽端口

  7. [Angular] Wrap a third party lib into service

  8. KVO的使用(1)

    1.在某个类中添加下面方法: -(void)viewWillAppear:(BOOL)animated{ [[NSNotificationCenter defaultCenter] addObserv ...

  9. 【BZOJ 1018】 [SHOI2008]堵塞的交通traffic

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1018 [题意] [题解] 按照这里的题解写的http://blog.csdn.net/ ...

  10. Python应用库大全总结

    学python,想必大家都是从爬虫开始的吧.毕竟网上类似的资源很丰富,开源项目也非常多. python学习网络爬虫主要分3个大的版块:抓取,分析,存储 当我们在浏览器中输入一个url后回车,后台会发生 ...