반응형
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
// Directive for the data model.
using LocalDatabaseSample.Model;
namespace LocalDatabaseSample.ViewModel
{
public class ToDoViewModel : INotifyPropertyChanged
{
// LINQ to SQL data context for the local database.
private ToDoDataContext toDoDB;
// Class constructor, create the data context object.
public ToDoViewModel(string toDoDBConnectionString)
{
toDoDB = new ToDoDataContext(toDoDBConnectionString);
}
//
// TODO: Add collections, list, and methods here.
//
// Write changes in the data context to the database.
public void SaveChangesToDB()
{
toDoDB.SubmitChanges();
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
// Used to notify Silverlight that a property has changed.
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
// Directive for the data model.
using LocalDatabaseSample.Model;
namespace LocalDatabaseSample.ViewModel
{
public class ToDoViewModel : INotifyPropertyChanged
{
// LINQ to SQL data context for the local database.
private ToDoDataContext toDoDB;
// Class constructor, create the data context object.
public ToDoViewModel(string toDoDBConnectionString)
{
toDoDB = new ToDoDataContext(toDoDBConnectionString);
}
//
// TODO: Add collections, list, and methods here.
//
// Write changes in the data context to the database.
public void SaveChangesToDB()
{
toDoDB.SubmitChanges();
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
// Used to notify Silverlight that a property has changed.
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
이것은 ViewModel의 템플릿입니다. LocalDatabaseSample.Model 네임스페이스에 대한 지시문을 사용하여 이전 단원에서 만든 LINQ to SQL 데이터 모델을 참조합니다. ViewModel은 변경 추적을 위한 INotifyPropertyChanged 인터페이스를 구현합니다.
ViewModel의 핵심 기능은 로컬 데이터베이스에서 작업을 수행하는 것입니다. LINQ to SQL 데이터 컨텍스트인 toDoDB는 ViewModel 전체에서 참조되며 ViewModel의 생성자에서 생성됩니다. SaveChangesToDB 메서드는 일반 용도의 저장 메커니즘을 뷰에 제공합니다.
반응형
'WINDOWS PHONE' 카테고리의 다른 글
SQL CE 데이터 타입 (0) | 2012.03.26 |
---|---|
Windows Phone에 대한 문화권 및 언어 지원 (0) | 2012.03.26 |
로컬 데이터베이스 테이블을 나타내는 클래스인 엔터티의 기본 템플릿 (0) | 2012.03.25 |
Windows phone 로컬 데이터베이스 응용프로그램(MVVM포함) 만들기 링크 (0) | 2012.03.24 |
Silverlight for Windows Phone ToolKit 사이트 링크 (0) | 2012.03.24 |