WPF中的验证(客户端-服务器应用程序) [英] Validation in WPF (client-server application)

查看:207
本文介绍了WPF中的验证(客户端-服务器应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了客户端服务器应用程序(数据访问层之上的WCF层)和具有WPF应用程序的客户端.由于我所有的类都在服务器端(在WCF层中),我如何验证这些wpf客户端形式?

解决方案

以下文本框的文本内容该示例绑定到名为ods的绑定源对象的Age属性(类型为int).绑定设置为使用名为AgeRangeRule的验证规则,因此,如果用户输入非数字字符或小于21或大于130的值,则文本框旁边会出现一个红色的感叹号,并且工具提示带有当用户将鼠标移到文本框上时,会出现错误消息.

示例代码为:

 <   TextBox    名称  ="    宽度  ="    ="  
 
                     span>      Validation.ErrorTemplate   ="  
 
                     span>     样式   {StaticResource textBoxInError}" 
                     span>      Grid.Row   ="     ="   1" 保证金  > 2"  > 
  <   TextBox.Text  > 
    <  绑定    ="  年龄"    {StaticResource ods }" 
                     span>          UpdateSourceTrigger   ="    > 
      <   Binding.ValidationRules  > 
        <   c:AgeRangeRule    最小  ="   Max    130 " > 
      <  /Binding.ValidationRules  > 
    <  /Binding  > 
  <  /TextBox.Text  > 
<  /TextBox  >  


i have created client server application(WCF layer over Data access layer) and client with WPF application. As my all classes are on server side(in WCF layer) how can i validate these wpf client forms???

解决方案

The text content of the TextBox in the following example is bound to the Age property (of type int) of a binding source object named ods. The binding is set up to use a validation rule named AgeRangeRule so that if the user enters non-numeric characters or a value that is smaller than 21 or greater than 130, a red exclamation mark appears next to the text box and a tool tip with the error message appears when the user moves the mouse over the text box.

Sample code is:

<TextBox Name="textBox1" Width="50" FontSize="15"

         Validation.ErrorTemplate="{StaticResource validationTemplate}"

         Style="{StaticResource textBoxInError}"

         Grid.Row="1" Grid.Column="1" Margin="2">
  <TextBox.Text>
    <Binding Path="Age" Source="{StaticResource ods}"

             UpdateSourceTrigger="PropertyChanged" >
      <Binding.ValidationRules>
        <c:AgeRangeRule Min="21" Max="130"/>
      </Binding.ValidationRules>
    </Binding>
  </TextBox.Text>
</TextBox>


这篇关于WPF中的验证(客户端-服务器应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆