Created
May 10, 2012 05:30
-
-
Save runceel/2651233 to your computer and use it in GitHub Desktop.
WCF RIA ServicesのCompletedイベントのお試し
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ServiceModel.DomainServices.Client; | |
using System.Windows; | |
using System.Windows.Controls; | |
using SilverlightApplication1.Web; | |
namespace SilverlightApplication1 | |
{ | |
/// <summary> | |
/// Button2つとDataGridを1つ適当に置いた画面のコードビハインド | |
/// </summary> | |
public partial class MainPage : UserControl | |
{ | |
private DomainService1 service; | |
private LoadOperation<Person> op; | |
public MainPage() | |
{ | |
InitializeComponent(); | |
} | |
private void Button_Click_1(object sender, RoutedEventArgs e) | |
{ | |
// 実行するだけしとく | |
// データのロードが終わったらDataGridに表示されるように | |
// 画面に置いたDataGridのItemsSourceを設定しておく | |
this.service = new DomainService1(); | |
this.dataGrid.ItemsSource = service.Persons; | |
var q = service.GetPeopleQuery(); | |
op = service.Load(q); | |
} | |
private void Button_Click_2(object sender, RoutedEventArgs e) | |
{ | |
// LoadOperation<T>のCompletedイベントを購読する | |
// 処理が完了している状態でイベントを購読してもCompletedイベントが発生する | |
op.Completed += (_, args) => | |
{ | |
MessageBox.Show("Completed"); | |
}; | |
} | |
} | |
// サーバーサイドのDomainServiceの実装 | |
//namespace SilverlightApplication1.Web | |
//{ | |
// using System.Collections.Generic; | |
// using System.ComponentModel.DataAnnotations; | |
// using System.Linq; | |
// using System.ServiceModel.DomainServices.Hosting; | |
// using System.ServiceModel.DomainServices.Server; | |
// // TODO: アプリケーション ロジックを含むメソッドを作成します。 | |
// [EnableClientAccess()] | |
// public class DomainService1 : DomainService | |
// { | |
// public IEnumerable<Person> GetPeople() | |
// { | |
// return Enumerable.Range(1, 10).Select(i => | |
// new Person { Id = i, Name = "田中 太郎" + i }); | |
// } | |
// } | |
// public class Person | |
// { | |
// [Key] | |
// public int Id { get; set; } | |
// public string Name { get; set; } | |
// } | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment