Advertisement
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 NonTrivialDataBindingDemoVS
- {
- class ItemPage : ContentPage
- {
- public ItemPage()
- {
- var titleViewModel = new TitleViewModel();
- titleViewModel.Title = "First";
- this.BindingContext = titleViewModel;
- var titleEntry = new Entry()
- {
- HorizontalOptions = LayoutOptions.FillAndExpand
- };
- titleEntry.SetBinding(Entry.TextProperty, new Binding("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) =>
- {
- await DisplayAlert("Item Object", "Title property: " + titleViewModel.Title.ToString(), "OK");
- };
- Button buttonUpdate = new Button
- {
- Text = "Update the Data Model",
- FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.Fill
- };
- buttonUpdate.Clicked += async (sender, e) =>
- {
- titleViewModel.Title = "Data Model Updated";
- await DisplayAlert("ItemObject", "Title property: " + titleViewModel.Title.ToString(), "OK");
- };
- Content = new StackLayout
- {
- Children = { titleEntry, buttonDisplay, buttonUpdate }
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement