zoukankan      html  css  js  c++  java
  • Silverlight验证相关

    asp.net mvc中有验证,当然在silverlight中也包含有验证规则的但这个就离不开mvvm(其实就是实体层,页面这些东西的组成,没有用过呀,悲哀!连这个概念都理解不了)。

    关于MVVM验证使用比较地道的用法可以参考:http://blog.csdn.net/junny12345/article/details/6185134

    先不说其他的,东西是一步一步学习而积累的。

    首先,需要验证一般动态绑定一些实体,但不绑定是不是可以呢?我没有尝试过,想象着我们可以这样做:

    public class MainPage:UserControl

    {

         [Required]     // 是不是可以这样呢?

         public int Zip{get;set;}

    }

    当然实体下是可以的:

    public class User

    {

           private string name;

           public int Age{get;set;}

           public string Name{

                 get{return name;}

                 set{

                      if(string.IsNullOrEmpty(value))

                      {

                           throw new ValidationException("name is required.");

                      }

                      name=value;

                 }

           }

    }

    public class MainPage:UserControl

    {

           public MainPage()

           {

                 InitializeComponent();

                 this.DataContext=new User();

           }

    }

    MainPage.xaml

    <Grid>

       <TextBlock x:Name="tbName" Text="Name"></TextBlock>

       <TextBox x:Name="txtName" Text="{Binding Name,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True }"></TextBox>

    </Grid>

    参考:http://www.codeproject.com/Articles/86955/Silverlight-Data-Validation-Tip-of-the-Day-Part

  • 相关阅读:
    51nod1260
    51nod1327
    51nod1342
    51nod1479
    LOJ6088
    51nod1634
    51nod1778
    JAVA循环结构学校上机经常遇到的几题 笔记
    B. The Number of Products(Codeforces Round #585 (Div. 2))
    A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
  • 原文地址:https://www.cnblogs.com/yy3b2007com/p/4318677.html
Copyright © 2011-2022 走看看