<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. Web报表工具FineReport实现EXCEL数据导入自由报表

    在制作填报报表的时候.对于空白填报表,经常导出为Excel,派发给各部门人员填写后上交.怎样能避免手动输入,直接将Excel中的数据导入到填报表中提交入库呢? 这里以一个简单的员工信息填报演示样例进行 ...

  2. OpenCV编译步骤

    作者:朱金灿 来源:http://blog.csdn.net/clever101 1. 从网上下载OpenCV安装包,然后安装. 2. 打开CMake 2.8设置源码路径和生成的VS工程文件路径.(首 ...

  3. tig install ncursesw

    ./configure --prefix=/home/xxx/.local/ --with-ncursesw make[xxx$ ldd src/tig linux-vdso.so.1 => ( ...

  4. spring mvc redirect 重定向 跳转并传递参数

    在项目中做form表单功能提交时,防止用户客户端后退或者刷新时重复提交问题,需要在服务端进行重定向跳转,具体跳转方式有以下几种方式: 公用代码: @RequestMapping(value=" ...

  5. 学习web开发遇到几个细节问题

    1.在jsp中使用jsp表达式在input标签中时,避免直接和结束"/"相连 2.提取input select 标签内的内容,使用...value提取其值 3.form中含有一个o ...

  6. eclipse 编写scala代码时提示computing additional info

    window->proference,把方框中那两个选项去掉不选,保存即可(或者只选择scala completions(java sources)),(只不过这么做之后就没有代码提示了)遇到这 ...

  7. Web静态服务器

    Web静态服务器 编程微刊 Web静态服务器-1-显示固定的页面 #coding=utf-8 import socket def handle_client(client_socket): " ...

  8. Centos root权限的变化

    方法一:更改 /etc/sudoers 文件, 找到以下一行,把前面的凝视(#)去掉 ## Allows people in group wheel to run all commands %whee ...

  9. MapReduce 切片机制源码分析

    总体来说大概有以下2个大的步骤 1.连接集群(yarnrunner或者是localjobrunner) 2.submitter.submitJobInternal()在该方法中会创建提交路径,计算切片 ...

  10. Smart internet of things services

    A method and apparatus enable Internet of Things (IoT) services based on a SMART IoT architecture by ...