smeacham

ItemPage.cs

Jun 2nd, 2016
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 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 TrivialDataBindingDemoVS
  10. {
  11.     class ItemPage : ContentPage
  12.     {
  13.         public ItemPage()
  14.         {
  15.             var item = new Item { Title = "First", Description = "1st item" };
  16.  
  17.             var titleEntry = new Entry()
  18.             {
  19.                 HorizontalOptions = LayoutOptions.FillAndExpand
  20.             };
  21.  
  22.             // specify the source data model
  23.             // this.BindingContext = item; // bind at the page level
  24.             titleEntry.BindingContext = item; // or bind at the view level
  25.  
  26.             // Pair the source property with the target view property
  27.             titleEntry.SetBinding(Entry.TextProperty, "Title");
  28.  
  29.             Button buttonDisplay = new Button
  30.             {
  31.                 Text = "Display Item Value",
  32.                 FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
  33.                 HorizontalOptions = LayoutOptions.Center,
  34.                 VerticalOptions = LayoutOptions.Fill
  35.             };
  36.  
  37.             buttonDisplay.Clicked += async (sender, e) =>
  38.             {
  39.                 item.Title = "You won't see this!";
  40.                 await DisplayAlert("Item Object", "Title property: " + item.Title.ToString(), "OK");
  41.             };
  42.  
  43.             Content = new StackLayout
  44.             {
  45.                 Children = { titleEntry, buttonDisplay }
  46.             };
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment