public AddManViewModel(INavigation navigation, PeopleListType people) { this.navigation = navigation; if (people.Image == null) { Picture = ImageSource.FromFile("gachi.jpg"); } else { Picture = people.Image; } ButtonText = "Edit"; IsEditable = false; Profession = people.Profession; Name = people.Name; Description = people.Description; EditCommand = new Command(() => { if (!IsEditable) { IsEditable = true; ButtonText = "Save"; } else { ButtonText = "Edit"; var newPeople = new PeopleListType { Description = this.Description, Image = Picture, Name = this.Name, Profession = this.Profession }; MessagingCenter.Send(this, "update", newPeople); IsEditable = false; } }); ChangeImageCommand = new Command(async() => { if (IsEditable) { MessagingCenter.Subscribe <AddingImageViewModel, ImageSource>(this, "image", (model, source) => { Picture = source; MessagingCenter.Unsubscribe <AddingImageViewModel, ImageSource>(this, "image"); }); await navigation.PushAsync(new SelectImageView()); } }); UpdateProfession = new Command(async() => { if (IsEditable) { MessagingCenter.Subscribe <ChangeProfessionViewModel, string>(this, "job", (model, source) => { Profession = source; MessagingCenter.Unsubscribe <AddingImageViewModel, ImageSource>(this, "job"); }); await navigation.PushAsync(new UpdateProfessionView()); } }); }
public AddingManPage(PeopleListType people) { BindingContext = new AddManViewModel(Navigation, people); InitializeComponent(); }