Advertisement
smeacham

ItemPage.cs

Jun 2nd, 2016
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using Xamarin.Forms;
  8.  
  9. namespace NonTrivialDataBindingDemoVS
  10. {
  11.     class ItemPage : ContentPage
  12.     {
  13.         public ItemPage()
  14.         {
  15.             var titleViewModel = new TitleViewModel();
  16.             titleViewModel.Title = "First";
  17.  
  18.             this.BindingContext = titleViewModel;
  19.  
  20.             var titleEntry = new Entry()
  21.             {
  22.                 HorizontalOptions = LayoutOptions.FillAndExpand
  23.             };
  24.             titleEntry.SetBinding(Entry.TextProperty, new Binding("Title"));
  25.  
  26.             Button buttonDisplay = new Button
  27.             {
  28.                 Text = "Display Item Value",
  29.                 FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
  30.                 HorizontalOptions = LayoutOptions.Center,
  31.                 VerticalOptions = LayoutOptions.Fill
  32.             };
  33.  
  34.             buttonDisplay.Clicked += async (sender, e) =>
  35.             {
  36.                 await DisplayAlert("Item Object", "Title property: " + titleViewModel.Title.ToString(), "OK");
  37.             };
  38.  
  39.             Button buttonUpdate = new Button
  40.             {
  41.                 Text = "Update the Data Model",
  42.                 FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
  43.                 HorizontalOptions = LayoutOptions.Center,
  44.                 VerticalOptions = LayoutOptions.Fill
  45.             };
  46.  
  47.             buttonUpdate.Clicked += async (sender, e) =>
  48.             {
  49.                 titleViewModel.Title = "Data Model Updated";
  50.                 await DisplayAlert("ItemObject", "Title property: " + titleViewModel.Title.ToString(), "OK");
  51.             };
  52.  
  53.             Content = new StackLayout
  54.             {
  55.                 Children = { titleEntry, buttonDisplay, buttonUpdate }
  56.             };
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement