![]() So my answer is to put the Type of the page in the Model but not restricting the View or the ViewModel to work with it also if one so chooses. I racked my brains on this a few days hitting the same hurdle when I switched to Xamarin development. We may even close page now from view model with Parent.PopAsync () XAML xmlns:viewModels="clr-namespace:yournamespace.ViewModels"Ĭhild viewmodel public class cPetEventsListVm : cMyBaseVmĪnd now, all around child view model we can use Page like Parent.DisplayAlert, or etc ![]() Get => (ContentPage)GetValue(ParentProperty) public static BindableProperty ParentProperty = BindableProperty.Create("Parent", typeof(ContentPage), typeof(cMyBaseVm), null, BindingMode.OneWay) Viewmodel public class cMyBaseVm : BindableObject started using this in my base class for viewmodels Somewhere in viewmodel void AddRecord(ContentPage parent)Ģ. Viewmodel constructor cmdAddRecord = new Command(AddRecord) You can then use this property for navigation: public class LocalAccountViewModel : INotifyPropert圜hanged Then in your VM, add a INavigation property and change the constructor to accept a INavigation. Note the VM constructor takes now a INavigation parameterīindingContext = new LocalAccountViewModel(Navigation) Since pages inherit from VisualElement, they directly inherit the Navigation property.Ĭode behind file: public class SignIn : ContentPage One way is you can pass the Navigation through the VM Constructor. Propert圜hanged?.Invoke(this, new Propert圜hangedEventArgs(PropertyName)) Protected virtual void OnPropert圜hanges( string PropertyName = null) Public event Propert圜hangedEventHandler Propert圜hanged This.ContinueBtnClicked = new Command(Goto) Here is my ViewModel: public class LocalAccountViewModel : INotifyPropert圜hanged As i cannot do Navigation.PushAsync(new ()) in ViewModel because it only possible in Code-Behid file. I am working on xamarin.form cross-platform application, i want to navigate from one page to another on button click.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |