TwoWay データバインド


  Class1.cs



using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Diagnostics;

namespace PhoneApp7
{
	public class Class1 : INotifyPropertyChanged
	{

		// チェックボックス用プロパティ
		// ※ TwoWay でセットされる様子をチェックする為にコードを記述しています
		private bool _CheckBoxSetting;
		public bool CheckBoxSetting {
			get {
				return _CheckBoxSetting;
			}
			set {
				_CheckBoxSetting = value;
				Debug.WriteLine("CheckBoxSetting にデータがセットされました" + value);
			} 
		}

		public Class1()
		{

			WebClient webClient = new WebClient();

			webClient.DownloadStringCompleted += 
				new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
			// 外部サービスから文字列を取得
			webClient.DownloadStringAsync(new System.Uri("http://textt.net/sworc/20120925064853.txt"));
		}

		private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
		{
			if (e.Error != null)
			{
				Deployment.Current.Dispatcher.BeginInvoke(() =>
				{
					Debug.WriteLine(e.Error.Message);
				});
			}
			else
			{
				// プロパティにセット
				this.CheckBoxSetting = bool.Parse(e.Result);
				NotifyPropertyChanged("CheckBoxSetting");
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;
		public void NotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this,
					new PropertyChangedEventArgs(propertyName));
			}
		}
	}

}











  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ