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 :)

  • 相关阅读:
    201671030116宋菲菲 实验三作业互评与改进报告
    通读《构建之法》提出问题
    201671010460-朱艺璇-实验四附加实验
    201671010460朱艺璇 词频统计软件项目报告
    201671010460朱艺璇 实验三作业互评与改进报告
    阅读《现代软件工程—构建之法》提出的问题
    手把手带你了解消息中间件(3)——RocketMQ
    字符编码的历史由来
    linux常用命令
    linux各目录及重要目录的详细介绍
  • 原文地址:https://www.cnblogs.com/sunjunlin/p/2003075.html
Copyright © 2011-2022 走看看