실버라이트 초간단 데이터 바인딩
1.ADO.NET Entity Data Model 을 만듭니다 (서버측)
2. 그런다음 데이터베이스에 접근할수 있는 ado.net Data Service 를 만들어줍니다. (서버측)
만들어진 Ado.Net Data Service
3.실버라이트 프로젝트에서 웹서비스를 참조합니다.
4.데이터그리드에 데이터를 바인딩 합니다.
아래는 간단한 소스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using System.Collections.ObjectModel;
using System.ComponentModel;
using BM.ServiceReference1;
namespace BM.CodeTest
{
public partial class Delete : UserControl
{
ServiceReference1.TEST_BOOKEntities svcContext;
ObservableCollection<ServiceReference1.BOOK> ObsvBookCollrection;
BooksDS bookDs;
public Delete()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Delete_Loaded);
}
void Delete_Loaded(object sender, RoutedEventArgs e)
{
svcContext = new TEST_BOOKEntities(new Uri("BookWebDataService.svc", UriKind.Relative));
ObsvBookCollrection = new ObservableCollection<BOOK>();
bookDs = new BooksDS();
DataServiceQuery<BOOK> query = (DataServiceQuery<BOOK>)
(from c in svcContext.BOOK select c);
query.BeginExecute(GetDataCallback, query);
}
#region 셀렉트
void GetDataCallback(IAsyncResult result)
{
try
{
DataServiceQuery<BOOK> queryResult =
(DataServiceQuery<BOOK>)result.AsyncState;
IEnumerable<BOOK> results =
queryResult.EndExecute(result);
foreach (var item in results)
{
bookDs.Add(item);
}
grdList.ItemsSource = bookDs;
MessageBox.Show("도서목록가져오기 완료");
}
catch (DataServiceRequestException ex)
{
}
}
#endregion
}
}
5.테스트 끝~
'WPF' 카테고리의 다른 글
| SplashScreen 만들기 (0) | 2009.12.15 |
|---|---|
| 초간단 실버라이트 웹서비스 사용하기 (0) | 2009.06.30 |
| 컨테이너(Container) (0) | 2009.06.03 |
| 모듈화 (0) | 2009.06.03 |
| XML , RSS 기사받아오기 및 웹서비스로 다시 보내주기 (0) | 2009.05.29 |
| IValueConverter 데이터 변환 (0) | 2009.05.28 |
| INotifyPropertyChanged 변경알림 (0) | 2009.05.28 |
| 델리게이트(delegate)로 유저컨트롤 이벤트 케치하기 (0) | 2009.05.28 |
| 초간단 컬렉션에 바인딩하고 마스터/세부 뷰 만들기 (0) | 2009.05.28 |
| Silverlight SDK Samples (0) | 2009.05.28 |