使用企业库配置文件验证绑定到Double类型的ViewModel属性的文本框 [英] Validation of Textbox bound to ViewModel Property of Double type using Enterprise Library Configuration file

查看:58
本文介绍了使用企业库配置文件验证绑定到Double类型的ViewModel属性的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用棱镜和Enterprise Library 5验证模块来制作MVVM模式.
我有一个View-ViewModel和一个数据访问层(DAL),其中包含带有数据库表字段的业务实体的类文件. Nullable"Double Type"的ViewModel中用Temperature属性映射的View中的TextBox,而View Model属性又又映射为Nullable"Double Type"的DAL的Temperature属性.
问题是我必须使用带有RegEx验证程序的validation.config文件中的规则集在ViewModel中使用Ruleset在ViewModel中执行工厂验证,以检查如果Temperature字段为+ ve double值",但恐怕它不起作用. validate.config如下:-

Hi All,
I am working on MVVM pattern, using prism and Enterprise Library 5 validation block.
I have a View-ViewModel and a Data Access Layer(DAL) containing the class files with business entities of database table fields.
The TextBox in View mapped with Temperature property in ViewModel of Nullable "Double Type", while the View Model property is inturn mapped to DAL''s Temperature property again of Nullable "Double Type".
The problem is I have to perform factory validation in ViewModel using the Ruleset from validation.config file with RegEx validator for checking "if the Temperature field is +ve double value", but I am afraid its not working.
The validation.config is as below:-

<type name="ViewModels.ViewModel">
      assemblyName="Assemblyname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=673ed9739f7ac7b7"&gt;
      <ruleset name="RulesetName">
        <properties>         <property name="Temperature">
            <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RegexValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
              pattern="^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$" options="IgnoreCase" messageTemplate="Number should be positive value"
              name="Regular Expression Validator" &gt;          </validator></property>

与数据库中的LiquidTemperature表映射的DAL类DBTemp.cs包含以下属性:-

The DAL Class DBTemp.cs mapped with LiquidTemperature Table in database contains a property as below:-

public Nullable &lt;double&gt; Temperature
        {
            get { return Temp; }
            set { Temp = value; OnPropertyChanged("Temperature"); }
        }



视图模型类包含如下属性:-



The View Model Class contains a property as below:-

private DAL.LiquidTemperature _lqTemp;
  public Nullable <double> Temperature
        {
            get { return _lqTemp.Temp; }
            set { _lqTemp.Temp = value; RaisePropertyChanged("Temperature"); }
        }


视图包含以下文本:-


The View Contains below text:-

<textbox grid.column="1" maxlength="4" name="txtTemparature">
                           <textbox.text>
                                <binding path="Temparature" mode="TwoWay" updatesourcetrigger="PropertyChanged" validatesonexceptions="True" notifyonvalidationerror="True">                                    <binding.validationrules>
<vab:validatorrule rulesetname="RulesetName" sourcetype="{x:Type vm:ViewModelName}" validationstep="UpdatedValue" sourcepropertyname="Temparature" validationspecificationsource="Configuration" xmlns:vab="#unknown">                                    <binding.validationrules>                               </binding.validationrules></vab:validatorrule></binding.validationrules></binding>
                            </textbox.text>
                        </textbox>

请帮助我.
在此先感谢

Please help me.
Thanks in Advance

推荐答案

"options =" IgnoreCase"messageTemplate =" Number应该为正值 name =正则表达式验证器"& gt; </validator></property>
" options="IgnoreCase" messageTemplate="Number should be positive value" name="Regular Expression Validator" &gt; </validator></property>

用数据库中的LiquidTemperature Table映射的DAL类DBTemp.cs包含如下属性:-

The DAL Class DBTemp.cs mapped with LiquidTemperature Table in database contains a property as below:-

public Nullable &lt;double&gt; Temperature
        {
            get { return Temp; }
            set { Temp = value; OnPropertyChanged("Temperature"); }
        }



视图模型类包含如下属性:-



The View Model Class contains a property as below:-

private DAL.LiquidTemperature _lqTemp;
  public Nullable <double> Temperature
        {
            get { return _lqTemp.Temp; }
            set { _lqTemp.Temp = value; RaisePropertyChanged("Temperature"); }
        }


视图包含以下文本:-


The View Contains below text:-

<textbox grid.column="1" maxlength="4" name="txtTemparature">
                           <textbox.text>
                                <binding path="Temparature" mode="TwoWay" updatesourcetrigger="PropertyChanged" validatesonexceptions="True" notifyonvalidationerror="True">                                    <binding.validationrules>
<vab:validatorrule rulesetname="RulesetName" sourcetype="{x:Type vm:ViewModelName}" validationstep="UpdatedValue" sourcepropertyname="Temparature" validationspecificationsource="Configuration" xmlns:vab="#unknown">                                    <binding.validationrules>                               </binding.validationrules></vab:validatorrule></binding.validationrules></binding>
                            </textbox.text>
                        </textbox>

请帮助我.
在此先感谢

Please help me.
Thanks in Advance


这个应用程序有多大?裁切棱镜和企业库5揭示了一种更易于管理的解决方案,这并非罕见.使用这些框架构建时,许多解决方案会变得不必要地混乱.

如果您正在开发一个数兆字节的解决方案,并且不包括生成的代码,那么它们可能会占有一席之地-否则,它们通常只是浪费时间和精力.

无论如何,尝试了一个看起来像这样的正则表达式:
How large is this application? It''s not unusual to find that trimming away prism and the Enterprise Library 5, reveals a much more manageable solution. Many solution becomes unnecessarily cluttered when built using those frameworks.

If you are working on a multi megabyte solution, and that excludes generated code, they may have a place - otherwise they are often just a waste of time and effort.

Anyway, tried a regex looking similar to this:
^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?




最好的问候
Espen Harlinn



Best regards
Espen Harlinn


这篇关于使用企业库配置文件验证绑定到Double类型的ViewModel属性的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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