zoukankan      html  css  js  c++  java
  • 我的第一个实现Silverlight4 with MVVM and Ria Service

    My First implementation in Silverlight4 with MVVM and Ria Service

    This is my first practices in silverlight4  using MVVM pattern and Ria Service  to only show data in the gridview

    please walk with me in this steps

    1-adding my framework

    2-adding my ria service class DomainService1

    3-in the silverlight project make the following

    a)add a new folder and call it ViewModel

    b)insert into the view model folder a c# class and Call it ViewModelBase

    4-in the ViewModelBase Class make the follwing code

    public class ModelViewBase : INotifyPropertyChanged

    {
    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(string propertyName)

    {

    if (PropertyChanged != null)

    {

    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

    }

    }

    }

    the previous class inherited from INotifyPropertyChanged and implement it

    note)this INotifyPropertyChanged interface in the System.ComponentModel

    5-Adding a new class for each page “each view” like EmployeePageViewModel

    this calss will be the following code :

    public class EmployeePageViewModel: ViewModelBase

    {

    private DomainService1 ds;

    public EmployeePageViewModel()

    {

    ds = new DomainService1();

    LoadOperation<Employee1> loadOperation = ds.Load<Employee1>(ds.GetEmployee1Query());

    loadOperation.Completed += new EventHandler(loadOperation_Completed);

    }
    private void loadOperation_Completed(object sender, EventArgs e)

    {

    LoadOperation<Employee1> loadOperation = sender as LoadOperation<Employee1>;

    if (loadOperation.HasError)

    {

    ListOfEmployees = null;

    loadOperation.MarkErrorAsHandled();

    }

    else

    ListOfEmployees = loadOperation.Entities.ToList();

    }

    private List<Employee1> _listOfEmployees;
    public List<Employee1> ListOfEmployees

    {

    get { return _listOfEmployees; }

    set {

    _listOfEmployees = value;

    RaisePropertyChanged(“ListOfEmployees”);

    }

    }
    }

    ===========================================================================

    in the EmployeePage.xaml

    make the following

    Add the name space

    1) xmlns:vm=”clr-namespace:SilverlightApplication3.ModelView”  which refer to the viewmodel in ur project

    2)add the items source property as the following ItemsSource=”{Binding ListOfEmployees}”

    ==================================================================

    in the EmployeePage.xaml.cs

    but the following code

    InitializeComponent();

    EmployeePageModelView vm = new EmployeePageModelView();

    this.DataContext = vm;

    ======================================================================

    thats all

    Happy programing :)

  • 相关阅读:
    【JavaScript从入门到精通】第二课 初探JavaScript魅力-02
    【JavaScript从入门到精通】第一课 初探JavaScript魅力-01
    程序员技术周刊
    【Geek软技能】程序员,为什么写不好一份简历?
    众里寻他千百度?No!这项技术只需走两步就能“看穿”你!
    PornHub 正式发布 AI自动标注色情演员引擎
    9 月份 GitHub 上最火的 JavaScript 开源项目!
    累了吗?来挑战一下算法趣题,看看自己是哪个段位的程序猿吧!
    Chrome 开发者控制台中,你可能意想不到的功能
    现代软件工程 作业 最后一周总结
  • 原文地址:https://www.cnblogs.com/sunjunlin/p/2003075.html
Copyright © 2011-2022 走看看