ソース掲示板




すべてから検索

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

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

対象スレッド 件名: Xaml 画面にデータをバインドするクラスのテンプレート
名前: lightbox
処理選択
パスワード

件名 Xaml 画面にデータをバインドするクラスのテンプレート
名前 lightbox
コメント
http://goo.gl/KzS1i8《データ バインディングの概要》

@DIV
<!-- 一覧的なリストボックス -->
<ListBox
	x:Name="MainListBox"
	Margin="564,34,236,229"
	ItemsSource="{Binding Items}" Grid.Row="1">
	<ListBox.ItemTemplate>
		<DataTemplate>
			<StackPanel Margin="0,0,0,17" Width="432" Height="78">
				<TextBlock
					Text="{Binding LineOne}"
					TextWrapping="Wrap"/>
				<TextBlock
					Text="{Binding LineTwo}"
					TextWrapping="Wrap"
					Margin="12,-6,12,0" FontSize="24" />
			</StackPanel>
		</DataTemplate>
	</ListBox.ItemTemplate>
</ListBox>
@END

@DIV
MainViewModel mvm = JsonConvert.DeserializeObject<ItemViewModel>(JsonText);
MainListBox.DataContext = mvm;

@END

@DIV
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Collections.ObjectModel;


namespace BindingXaml {

	public class MainViewModel : INotifyPropertyChanged {
		public MainViewModel() 	{
			// バインド用のコレクションのインスタンスを設定
			this.Items = new ObservableCollection<ItemViewModel>();
		}

		// *****************************************************
		// バインド用のコレクションのプロパティ
		// *****************************************************
		public ObservableCollection<ItemViewModel> Items { get; private set; }

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