<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. ssh登录很慢,登录上去后速度正常问题的解决方法

    1. DNS反向解析的问题 OpenSSH在用户登录的时候会验证IP,它根据用户的IP使用反向DNS找到主机名,再使用DNS找到IP地址,最后匹配一下登录的IP是否合法.如果客户机的IP没有域名,或者 ...

  2. ios开发视频播放后台下载功能实现 :1,ios播放视频 ,包含基于AVPlayer播放器,2,实现下载,iOS后台下载(多任务同时下载,单任务下载,下载进度,下载百分比,文件大小,下载状态)(真机调试功能正常)

    ABBPlayerKit ios开发视频播放后台下载功能实现 : 代码下载地址:https://github.com/niexiaobo/ABBPlayerKit github资料学习和下载地址:ht ...

  3. DbVisualizer的使用

    DbVisualizer的使用 一. Db工具的使用,怎么新建一个数据库连接? 新建一个数据库连接,点击 Tools > Connection Wizard 来新建一个数据库: 或者直接点击 + ...

  4. BZOJ 2096 Pilots - 单调队列STL(deque)

    传送门 分析: 单调队列:维护两个递增.递减的队列,每次都加入新元素并更新,如果最大值(递减队首)-最小值(递增队首) > k,那么将最左段更新为前面两者中较前的那一个,并弹掉.用deque可以 ...

  5. c头文件(.h)的作用

    C语言的著作中,至今还没发现把.h文件的用法写的透彻的.在实际应用中也只能依葫芦画瓢,只知其然不知其所以然,甚是郁闷!闲来无事,便将搜集网络的相关内容整理一下,以便加深自己的理解 理论概述:.h中一般 ...

  6. VB的MSHFlexGrid控件内容导入Excel

    机房收费系统中有非常多窗口用到导出到Excel,说一下vb与Excel的交互,怎样才干将MSHFlexgrid中的内容导出到Excel. 首先在VB中加入引用Microsoft Excel 14.0 ...

  7. 【77.39%】【codeforces 734A】Anton and Danik

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. Servlet接口的实现类,路径配置映射,ServletConfig对象,ServletContext对象及web工程中文件的读取

    一,Servlet接口实现类:sun公司为Servlet接口定义了两个默认的实现类,分别为:GenericServlet和HttpServlet. HttpServlet:指能够处理HTTP请求的se ...

  9. spring sts4 如何添加tomcat 服务

    spring sts4 ide中已经没有集成tomcat运行服务器了,需要到点击Help-->Eclipse Marketplace中安装 Eclipse JST Server Adapters ...

  10. QImage学习学习

    QImage这个类之前用过,无外乎是加载一个图片文件显示出来,并没有做过多的研究,目前工作中用到了灰度图以及图片的像素操作,重新学习了下,记录记录. 一些基本操作方法 获取图像的首地址: const ...