ソース掲示板




すべてから検索

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

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

対象スレッド 件名: Windows Phone(C#) HTTP Get ( Post )
名前: lightbox
処理選択
パスワード

件名 Windows Phone(C#) HTTP Get ( Post )
名前 lightbox
コメント
@DIV
public partial class Page1 : PhoneApplicationPage
{

	MainViewModel mvm = new MainViewModel();

	public Page1()
	{
		InitializeComponent();

		WebClient webClient = new WebClient();
		webClient.DownloadStringCompleted +=
			new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
		// 外部サービスから文字列を取得
		webClient.DownloadStringAsync(new System.Uri("http://localhost/kouki_kadai/server.php?type=one&id=0005"));

	}

	private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
	{
		if (e.Error != null)
		{
		}
		else
		{

			Debug.WriteLine(e.Result);

			mvm = JsonConvert.DeserializeObject<MainViewModel>(e.Result);
			this.DataContext = mvm.items[0];

		}
	}

}
@END


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

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

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


[[画面定義]]
@DIV
<Grid x:Name="LayoutRoot" Background="Transparent">
	<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
		<StackPanel Margin="0,0,0,17" Width="432" Height="78">
			<TextBlock
				Text="{Binding TITLE}"
				TextWrapping="Wrap"
				Margin="12,-6,12,0"
				Style="{StaticResource PhoneTextSubtleStyle}"/>
		</StackPanel>
	</Grid>
</Grid>
@END


[[JSON データ]]
@DIV
{
    "items": [
        {
            "ID": "0005",
            "TITLE": "僕は友達が少ない NEXT",
            "SUMMARY": "聖クロニカ学園(せいクロニカがくえん)高等部2年生の羽瀬川小鷹は、転校から1か月経ってもその外見が原因で周囲にヤンキーと勘違いされ、クラスで浮いた存在であった。",
            "TV": "毎日放送",
            "PRODUCTION": "AIC Build",
            "START": "2013-01-17 00:00:00",
            "EXPECTATION": "3",
            "FF": "0"
        }
    ]
}
@END


[[ItemViewModel]]
@DIV
public class ItemViewModel : INotifyPropertyChanged
{

	private string _lineData;
	public string TITLE
	{
		get
		{
			return _lineData;
		}
		set
		{
			if (value != _lineData)
			{
				_lineData = value;
				NotifyPropertyChanged("TITLE");
			}
		}
	}


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