拡張子:txtvbswsfjsphpjavahtmlutf8sjis 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]; } } } MainViewModel 拡張子:txtvbswsfjsphpjavahtmlutf8sjis 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)); } } } 画面定義 拡張子:txtvbswsfjsphpjavahtmlutf8sjis <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> JSON データ 拡張子:txtvbswsfjsphpjavahtmlutf8sjis { "items": [ { "ID": "0005", "TITLE": "僕は友達が少ない NEXT", "SUMMARY": "聖クロニカ学園(せいクロニカがくえん)高等部2年生の羽瀬川小鷹は、転校から1か月経ってもその外見が原因で周囲にヤンキーと勘違いされ、クラスで浮いた存在であった。", "TV": "毎日放送", "PRODUCTION": "AIC Build", "START": "2013-01-17 00:00:00", "EXPECTATION": "3", "FF": "0" } ] } ItemViewModel 拡張子:txtvbswsfjsphpjavahtmlutf8sjis 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)); } } }
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]; } } }
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)); } } }
<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>
{ "items": [ { "ID": "0005", "TITLE": "僕は友達が少ない NEXT", "SUMMARY": "聖クロニカ学園(せいクロニカがくえん)高等部2年生の羽瀬川小鷹は、転校から1か月経ってもその外見が原因で周囲にヤンキーと勘違いされ、クラスで浮いた存在であった。", "TV": "毎日放送", "PRODUCTION": "AIC Build", "START": "2013-01-17 00:00:00", "EXPECTATION": "3", "FF": "0" } ] }
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)); } } }
拡張子:txtvbswsfjsphpjavahtmlutf8sjis private void button1_Click_1(object sender, RoutedEventArgs e) { WebClient HttpClient = new WebClient(); // ダウンロード完了後に呼び出されるイベントハンドラを設定 HttpClient.UploadStringCompleted += new UploadStringCompletedEventHandler(HttpPostCompleted); // POST 用 Http ヘッダの設定 HttpClient.Headers["Content-Type"] = "application/x-www-form-urlencoded"; // 送信 string url = "http://localhost/kouki_kadai/server.php"; string data_string = "type=dml&query=" + Uri.EscapeDataString("update アニメ set FF = 0 where ID= '0001'"); HttpClient.UploadStringAsync(new Uri(url), "POST", data_string); } void HttpPostCompleted(object sender, UploadStringCompletedEventArgs e) { if (e.Error == null) { // 指定したURIから読み込んだ文字列を取得 Debug.WriteLine(e.Result); MessageBox.Show("送信しました"); } else { MessageBox.Show("通信エラーが発生しました。\r\n" + e.Error.Message); } }
private void button1_Click_1(object sender, RoutedEventArgs e) { WebClient HttpClient = new WebClient(); // ダウンロード完了後に呼び出されるイベントハンドラを設定 HttpClient.UploadStringCompleted += new UploadStringCompletedEventHandler(HttpPostCompleted); // POST 用 Http ヘッダの設定 HttpClient.Headers["Content-Type"] = "application/x-www-form-urlencoded"; // 送信 string url = "http://localhost/kouki_kadai/server.php"; string data_string = "type=dml&query=" + Uri.EscapeDataString("update アニメ set FF = 0 where ID= '0001'"); HttpClient.UploadStringAsync(new Uri(url), "POST", data_string); } void HttpPostCompleted(object sender, UploadStringCompletedEventArgs e) { if (e.Error == null) { // 指定したURIから読み込んだ文字列を取得 Debug.WriteLine(e.Result); MessageBox.Show("送信しました"); } else { MessageBox.Show("通信エラーが発生しました。\r\n" + e.Error.Message); } }