Giter VIP home page Giter VIP logo

xamarinviewmodellocator's Introduction

forthebadge forthebadge

GitHub license Actions Status Actions Status GitHub last commit nuget


XamarinViewModelLocator

A super light-weight view model locator for Xamarin.Forms applications

Getting Started

Installation

  • Install nuget package(Xam.ViewModelLocator) into your .Net Standard or PCL project
  • Import name space in the view file and set the AutoWireViewModelProperty to true
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             xmlns:viewModelLocator="clr-namespace:XamarinViewModelLocator;assembly=XamarinViewModelLocator"
             viewModelLocator:ViewModelLocator.AutoWireViewModel="True"
             x:Class="TestApp.Views.MainPage">
 </ContentPage>

That's all...

Naming Convention

  • View Name can be anything
  • View Model's name must be ViewName+"ViewModel". e.g View's Name = MainPage, ViewModel's Name = MainPageViewModel
  • Soon this convention can be changed

Folder Convention

By convention it will look for the view in a "Views" folder/namespace and the view model in a "ViewModels" folder/namespace. This convention can be changed by passing a config file to the viewModel object on start up.

ViewModelLocator.Config = new Configuration().SetFolderNames("NewViewsFolderName", "NewViewModelsFolderName");

Construction Convention

  • If the view model has a parameterless constructor. It is used to create the object.
  • If the view model has dependencies, then the view model and it's dependencies will be resolved from a given container refrence.
  • Container refrence can be supplied by chaining a new method to the configuration object.
ViewModelLocator.Config = new Configuration().SetFolderNames("NewViewsFolderName", "NewViewModelsFolderName")
                                             .SetContainer(_containerRefrenceObject);

Note: Only chain the methods you need.

Supported Containers

  • AutoFac
  • Unity

Contributing

  • Create a Fork from this repository.
  • Clone your fork into your work station.
  • Switch to the development branch.
  • Make your changes on the development branch.
  • Push your changes to your fork.
  • Create a pull request back to the main repository.
  • Add a new remote called upstream to point to the main repository.

xamarinviewmodellocator's People

Contributors

ndubuisijr avatar

Stargazers

TotPeRo avatar  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.