ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文

  メンテナンス 前画面に戻る

対象スレッド 件名: ItemViewModel.cs
名前: lightbox
処理選択
パスワード

件名 ItemViewModel.cs
名前 lightbox
コメント
@DIV
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Net;
using System.Windows;
using System.Windows.Input;

namespace BindingXaml { 

	public class ItemViewModel : INotifyPropertyChanged 	{
		// *********************************************
		// エントリ
		// *********************************************
		private string _lineOne;
		public string LineOne 	{
			get { return _lineOne; }
			set {
				SetAndNotifyString(GetName(() => LineOne), ref _lineOne, value);
			}
		}

		// *********************************************
		// エントリ
		// *********************************************
		private string _lineTwo;
		public string LineTwo 	{
			get { return _lineTwo; }
			set {
				SetAndNotifyString(GetName(() => LineTwo), ref _lineTwo, value);
			}
		}

		// *********************************************
		// エントリ
		// *********************************************
		private string _lineThree;
		public string LineThree
		{
			get { return _lineThree; }
			set {
				SetAndNotifyString(GetName(() => LineThree), ref _lineThree, value);
			}
		}

		// *********************************************
		// 文字列プロパティ用のセットメソッド
		// *********************************************
		private void SetAndNotifyString(string PropName, ref string OldData, string NewData) {
			// 無駄の無いように、値が違った時だけ処理
			if (OldData != NewData) {
				// 値の変更
				OldData = NewData;
				// 値が変更された事をバインドシステムに通知
				NotifyPropertyChanged(PropName);
			}
		}

		// *********************************************
		// プロパティを文字列に変換するメソッド
		// *********************************************
		private string GetName<T>(Expression<Func<T>> e)
		{
			var member = (MemberExpression)e.Body;
			return member.Member.Name;
		}

		// *****************************************************
		// データが変更された事を通知する為の実装
		// *****************************************************
		public event PropertyChangedEventHandler PropertyChanged;
		private void NotifyPropertyChanged(String propertyName) {
			PropertyChangedEventHandler handler = PropertyChanged;
			if (null != handler) {
				handler(this, new PropertyChangedEventArgs(propertyName));
			}
		}
	}
}
@END