<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. [Linux] Search the contents of files using grep

    Learn the basic syntax for using grep to search the contents of a single file or files. It's like CM ...

  2. ios开发多选照片实现

    #import "ViewController.h" #import <Photos/Photos.h> @interface ViewController () &l ...

  3. Momentum(动量/冲量)的理解及应用

    1. 基本概念(Momentum vs SGD) Momentum 用于加速 SGD(随机梯度下降)在某一方向上的搜索以及抑制震荡的发生. GD(gradient descent) θt=θt−1−η ...

  4. 【poj 1704】Georgia and Bob

    Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9776 Accepted: 3222 Description Georgia a ...

  5. head first c 笔记&lt;3&gt; 之做一件事并把它做好

    1.标准输入.输出与重定向 scanf()和printf()分别为标准输入输出.默认的会从键盘得到数据,在显示器输出数据,是fscanf()和fprintf()函数的特例. 我们也能够用重定向来改变默 ...

  6. php课程 6-22 字符串格式化函数有哪些(精问)

    php课程 6-22 字符串格式化函数有哪些(精问) 一.总结 一句话总结: 1.猜测一下$_GET()怎么来的? 函数赋值给变量的操作:$_YZM=get();   这样就可以很好的解释哪些全局变量 ...

  7. 设计模式<面向对象的常用七大设计原则>

    面向对象设计的目标之一在于支持可维护性复用,一方面需要实现设计方案或者源码的重用,另一方面要确保系统能够易于扩展和修改,具有较好的灵活性. 常用的设计原则有七个原则: 1.单一职责原则(single ...

  8. Word Break II -- leetcode

    Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each ...

  9. 一起学Python:字符串介绍

    字符串介绍 <1>python中字符串的格式 如下定义的变量a,存储的是数字类型的值 a = 100 如下定义的变量b,存储的是字符串类型的值 b = "hello itcast ...

  10. VS2017 安装过程

    2017 安装过程 工欲善其事必先利其器 Visual Studio 2017 正式版官方下载地址:https://www.visualstudio.com/downloads/ 安装vs2017的时 ...