Giter VIP home page Giter VIP logo

eiadxp / mvvmtools Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 2.83 MB

A library that provide the following cross platform features: -Direct bind of the events (in your views) to the methods or commands (in your view models) in your XAML code -Creating a preview of your view model at design time -Easy way of creating commands in your view models.

License: MIT License

C# 96.52% Smalltalk 3.48%
mvvm mvvm-architecture mvvmcross mvvmlight mvvm-light mvvm-framework caliburn-micro catel csharp events

mvvmtools's Introduction

Installation:

Package Nuget
ClinicalOffice Nuget
ClinicalOffice.WPF Nuget
ClinicalOffice.XForms Nuget

A tiny library to help cross-platform MVVM developer to be more productive by adding some shared and platform specific features:

1.Shared Library:

To be installed on any .NET Standard 2.0 compatible project, usually where you define your view models. The main usage for this library is to help developer in creating commands in an easy way for the view models. It has also some basic classes to be used in the platform specified libraries (like command collection and basic implementation of event binding). You can create commands in a simple way:

using System;
using System.Windows.Input;
using MvvmTools;

namespace Sample
{
    public class ViewModel
    {
        public ViewModel()
        {
            ShowModelsCountCommand = Command.Create(ShowModelsCount);
        }
        public List<Model> Models { get; set; }

        public void ShowModelsCount() => ShowMessage(Models?.Count);
        public ICommand ShowModelsCountCommand { get; private set; }
    }
}

2.Platform Specific Library:

The first part of this library enables direct binding between events in your views and methods in the view models directly from XAML code Like:

<TextBox tools:Events.Bindings="LostFocus=Validate,GotFocus=Clear"/>

This will create two events bindings.... one will call method Validate on LostFocus event, and one will call Clear when event GotFocus is fired.... You can also pass single parameter to the method as Following:

<TextBox tools:Events.Bindings="LostFocus=Validate(!context),GotFocus=Clear(!sender)"/>

You can also use commands in the same way as methods and bind them to any event:

<TextBox tools:Events.Bindings="LostFocus=ValidateCommand(!context),GotFocus=ClearCommand(!sender)"/>

The Second part will enable a quick preview of you view models and its data inside your designer to give a better way of previewing your interface at design time. You can write the following in your WPF application (the magic happens in the line d:DataContext="{tools:DesignInstance Type=vm:ViewModel}"):

<Window x:Class="MvvmTools.Sample.WPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MvvmTools.Sample.WPF"
        xmlns:tools="clr-namespace:MvvmTools.WPF;assembly=MvvmTools.WPF"
        xmlns:vm="clr-namespace:MvvmTools.Sample;assembly=MvvmTools.Sample"
        mc:Ignorable="d"
        d:DataContext="{tools:DesignInstance Type=vm:ViewModel}"
        Title="MainWindow">
</Window>

In your xamarin forms (also pay attention to BindingContext="{tools:DesignInstance Type=vm:ViewModel}"):

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MvvmTools.Sample.XForms"
             xmlns:vm="clr-namespace:MvvmTools.Sample;assembly=MvvmTools.Sample"
             xmlns:tools="clr-namespace:MvvmTools.XForms;assembly=MvvmTools.XForms"
             BindingContext="{tools:DesignInstance Type=vm:ViewModel}"
             x:Class="MvvmTools.Sample.XForms.MainPage">
</ContentPage>

** PLEASE READ THE WIKI FOR MORE INFORMATIONS **

mvvmtools's People

Contributors

eiadxp avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

bubdm

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.