Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- namespace TrivialDataBindingDemoVS
- {
- class ItemPage : ContentPage
- {
- public ItemPage()
- {
- var item = new Item { Title = "First", Description = "1st item" };
- var titleEntry = new Entry()
- {
- HorizontalOptions = LayoutOptions.FillAndExpand
- };
- // specify the source data model
- // this.BindingContext = item; // bind at the page level
- titleEntry.BindingContext = item; // or bind at the view level
- // Pair the source property with the target view property
- titleEntry.SetBinding(Entry.TextProperty, "Title");
- Button buttonDisplay = new Button
- {
- Text = "Display Item Value",
- FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.Fill
- };
- buttonDisplay.Clicked += async (sender, e) =>
- {
- item.Title = "You won't see this!";
- await DisplayAlert("Item Object", "Title property: " + item.Title.ToString(), "OK");
- };
- Content = new StackLayout
- {
- Children = { titleEntry, buttonDisplay }
- };
- }
- }
- }
Add Comment
Please, Sign In to add comment