Skip to content

blounty/MiniVVM

Repository files navigation

MiniVVM

Define your views


  [assembly:MiniVVM.ExportView(typeof(ViewOne), typeof(ViewOneViewModel))]
  [assembly:MiniVVM.ExportView(typeof(ViewTwo), typeof(ViewTwoViewModel))]
  
  [assembly:MiniVVM.ExportView(typeof(ViewTwoTablet), typeof(ViewTwoViewModel), TargetIdiom.Tablet)]

Initialize on each platform


protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);
    global::MiniVVM.Engine.Minify();
    LoadApplication(new App());
}

Initialize your app


public App()
  {
    // The root page of your application
    MainPage = new NavigationPage(ViewFactory.Current.ResolveView());
  }

Setup your ViewModels


    public class ViewOneViewModel
    : ViewModel
    {

        string usersName;
        public string UsersName
        {
            get
            {
                return usersName;
            }
            set
            {
                RaiseAndUpdate(ref usersName, value);
                NavigateTo2Command.ChangeCanExecute();
            }
        }

        Command navigateTo2Command;
        public Command NavigateTo2Command
        {
            get
            {
                return navigateTo2Command;
            }
            set
            {
                RaiseAndUpdate(ref navigateTo2Command, value);
            }
        }

        public ViewOneViewModel()
        {
            NavigateTo2Command = new Command(NavigateTo2, () => !string.IsNullOrEmpty(UsersName));
        }

        void NavigateTo2()
        {
            Navigation.PushAsync(ViewFactory.Current.ResolveView(new Dictionary{{"UsersName", UsersName}}));
        }
    }
    

Passing data between ViewModels

When calling ResolveView and passing a dictionary of data we will automatically match up the keys to properties on the requested ViewModel and set the properties for you.


ViewFactory.Current.ResolveView(new Dictionary{{"UsersName", UsersName}});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages