Giter Club home page Giter Club logo

simplemvvm's Introduction

Simple Microsoft MVVM Toolkit Sample

POC minimal yet plausable MVVM app using Microsoft's MVVM Toolkit.

Description:

This project incorporates features that compensate for some of the limitations of Microsoft's MVVM Toolkit. The demo app is simple enough to be digestable yet complicated enough to be representative of real world MVVM usage.

Ancillary to the evaluation of MVVM Toolkit usage, this project also attempts to share code between WinUI 3 and UWP in a manner that minimizes the differences. Add an issue if you see ops for improvement on the consolidation.

Credits

Screenshots

Screenshot

Screenshot

Screenshot

Notes

What limitations?

Persently, when you create a new ViewModel, you have to remember to wire it into your Ioc. Most MVVM frameworks have this limitation.

A simple solution to this little detail is to use an attribute as shown below:

    [RegisterWithIoc(InstanceMode.Transient)]
    public class AboutViewModel : ObservableRecipient

This can be incorporated automatically via a project template whenever you generate a ViewModel class.

Have a look at App.xaml.cs to see the details of how this approach works.

Another missing capability from MVVM frameworks in general is the ability to send control events to your ViewModel. For the ShellViewModel in particular, there is no need to adhere to a strict MVVM approach.

Having EventToCommandBehavior allows you to work around issues such as the one shown below:

        <winui:NavigationView x:Name="NavigationView"
                              Header="{x:Bind ViewModel.Header, Mode=OneWay}"
                              IsBackButtonVisible="Collapsed"
                              Background="Transparent"
                              PaneDisplayMode="LeftCompact"
                              IsSettingsVisible="False">
            <i:Interaction.Behaviors>
                <ui:EventToCommandBehavior 
                            Event="ItemInvoked"
                            Command="{x:Bind ViewModel.ItemInvokedCommand}" 
                            PassArguments="true"/>
            </i:Interaction.Behaviors>

            ...

Navigation events and other like control events can be dispatched within the ShellViewModel to coordinate with other executive level control operations. Think of your ShellViewModel as your UI escape hatch where anything goes allowing the rest of your MVVM design to stay clean and sober.

Please let me know if you see ways to improve this sample or if you have a difference of opinion with the approach taken.

Lastly, the following binding expression: CommandParameter="{Binding ElementName=ContentFrame} was changed to CommandParameter="{x:Bind ContentFrame} due to a bug in WinUI 3 Preview 4.

Other than things that do not work yet, the differences between WinUI and UWP are fairly minor. You can leverage UWP to develop for WinUI today as demonstrated by SimpleMVVM.

simplemvvm's People

Stargazers

 avatar Justin Hachemeister avatar stevcode avatar  avatar Media Explorer avatar  avatar  avatar Themba avatar Anna Novikova avatar Laim avatar

Watchers

Mario Pintaric 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.