GithubHelp home page GithubHelp logo

markti / xamvvm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xamvvm/xamvvm

0.0 2.0 0.0 655 KB

Simple MVVM (Model, ViewModel, View) Framework for .Net - Xamarin.Forms compatible

License: Apache License 2.0

Makefile 0.29% C# 99.71%

xamvvm's Introduction

xamvvm

Simple, fast and lightweight MVVM Framework for Xamarin.Forms with fluent API

Features

  • Very Easy to use. Just mark your pages / models with empty interfaces IBasePage<TPageModelType> / IBasePageModel
  • PageModel first oriented Navigation
  • Automatic wiring of BindingContext (PageModels)
  • Pages / PageModels caching - more responsive UI experience!
  • You're not limited to any concrete implementation of Pages, PageModels
  • Fluent style extensions methods to write less code
  • Helper classes with ready to use INotifyPropertyChanged implementation eg. BasePageModel
  • Pages have override methods to respond / intercept navigation (eg. NavgationPushing, NavigationCanPush, etc.)
  • Strongly typed classes / methods / messaging
  • Dependency free ICommand implementation prevents multiple execution when previous execution not finished yet

Getting Started

Initialize the Framework

You have to create an instance of a IBaseFactory implementation and set it as the current factory to use

var factory = new XamvvmFormsPageFactory(this);
XamvvmCore.SetCurrentFactory(factory);

That's all :-)

The PageFactory will scan your assemblies at start up and link Pages and PageModels together according to the IBasePage definition on your Pages. (You can also register your Pages manually if you want to. See Wiki)

PageModel first navigation

All pushing and popping is always done from the PagewModel an not from Pages

var pageToPush = this.GetPageFromCache<DetailPageModel>();
await this.PushPageAsync(pageToPush);

// OR even shorter way:
this.PushPageFromCache<DetailPageModel>();

You can pass an int action too that is executed on the Pagemodel before displaying the page

await this.PushPageAsync(pageToPush, (pm) => pm.Init("blue", Color.Blue));

// OR even shorter way:
this.PushPageFromCache<DetailPageModel>((pm) => pm.Init("blue", Color.Blue));

Popping is as easy

await this.PopPageAsync();

All a page has to do is derive from IBasePage with the PageModelType this Page should be linked to.For the above example calls the used classes would like this.

public partial class DetailPage : ContentPage, IBasePage<DetailPageModel>
{
	public DetailPage()
	{
		InitializeComponent();
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Examples.DetailPage"
		Title="Detail Page">
	<ContentPage.Content>
		<Label Text="{Binding Text}" BackgroundColor="{Binding Color}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
	</ContentPage.Content>
</ContentPage>
public class DetailPageModel : IBasePageModel
{
	public void Init(string text, Color color)
	{
		Text = text;
		Color = color;
	}

	public Color Color
	{
		get { return GetField<Color>(); }
		set { SetField(value); }
	}

	public string Text
	{
		get { return GetField<string>(); }
		set { SetField(value); }
	}
}

You don't have to inherit from BasePageModel it's just an included convinience class

Please look into the Wiki for Detailed Information

NuGet

Support

Please ask questions in this issue We also have a channel in the xamarin slack channel #xamvvm (invitation https://xamarinchat.herokuapp.com/)

Example project

https://github.com/xamvvm/xamvvm/tree/master/examples

xamvvm's People

Contributors

daniel-luberda avatar escamoteur avatar markti avatar chrisway avatar lucecarter avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.