Giter VIP home page Giter VIP logo

mvvm-navigation's Introduction

Logo

MVVM-Navigation

What?

Navigation framework to allow true MVVM-like navigation in UAP (Universal App Platform).

Why?

Platform API supports only navigating to target Page type:

frame.Navigate(typeof(NewPage));

optionally passing in simple parameters:

frame.Navigate(typeof(NewPage), userId);

In your NewPage codebehind you then need to override OnNavigatedTo, get the navigation parameter and pass it to your viewmodel.

Not only is it a lot of repetitive work, but if you want to perform navigation in you viewmodel, this effectively breaks your separation of concerns and the MVVM pattern.

With the rise of UAP you also have to manually deal with different screen factors - on a small screen, you want to navigate to new page, but on a larger one you just want to bring in new view on the existing page.

You also have to manually take care of persisting and restoring your state to support tombstoning of your app.

How?

With the MVMM Navigation you can just write something like this:

navigationService.Navigate<NewViewModel>();

optionally passing even complex parameters:

navigationService.Navigate<NewViewModel, User>(new User { Id = 42 });

The NewViewModel just needs to implement the corresponding interface:

public interface IActivate
{
  void Activate();
}

public interface IActivate<TData>
{
  void Activate(TData data);
}

and the Activate method gets invoked when you navigate to the given viewmodel. To allow this navigation to viewmodels, the framework needs to know which view corresponds to which viewmodel. They way to set it up is described here.

There is more?

There are other cool features in the library. Following are noteble:

  • Viewmodel activation and deactivation - pass data to your viewmodels and let them gracefully deactivate or prevent deactivation (and hence navigation) altogether. Read more here.
  • Automatic state persistance for tombstoning - the data you send between viewmodels when navigating is persisted and automatically restored. Read more here.
  • Adaptive platform navigation - when navigating to new viewmodel, you may not always want to navigate to new Page - e.g. on a larger screen you want to remain on the existing Page and only navigate to new Page when the size of the Window shrinks. Read more here.

Where?

Install-Package Bezysoftware.Navigation -Pre

How do I start?

There is some plumbing needed to make all this work. This page describes all steps you need to undertake when setting up new project.

You can also take a look at the sample project located here (part of the main solution).

Also make sure to check out MVVM Dialogs which builds on top of this package and intruduces a simple way to show dialogs from ViewModels.

mvvm-navigation's People

Contributors

bezysoftware avatar mephistofeles avatar

Watchers

 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.