Use MVVM light in the Windows Universal app

Source: Internet
Author: User

New empty Universal App project, adding "MVVM Light libraries Only (PCL) NuGet" package in Project in Windows 8.1 and Windows Phone 8.1

Create a new view model class in shared project

usingGalasoft.mvvmlight;usingGalaSoft.MvvmLight.Command;usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceUniversal_mvvmlight. viewmodel{ Public classMainvm:viewmodelbase {Private stringMtitle ="HelloWorld";  Public stringTitle {Get{returnMtitle;} Set{mtitle=value; raisePropertyChanged ("Title"); }        }        PrivateRelaycommand Mbuttonclick;  PublicRelaycommand ButtonClick {Get            {                returnMbuttonclick?? (Mbuttonclick =NewRelaycommand (() =                {                     This. Title ="Fuck the world";            })); }        }    }}
MAINVM

To bind the view model directly in code behind without the view model locator

 Public MainPage ()        {            this. InitializeComponent ();              This New MAINVM ();        }

Next, Bind in XAML

<stackpanel orientation="Vertical"Verticalalignment="Center"Horizontalalignment="Center"> <textblock fontsize=" -"Foreground=" White"text="{Binding Title}"Verticalalignment="Center"Horizontalalignment="Center"></TextBlock> <button command="{Binding ButtonClick}"Content="Click Me"Fontsize=" -"></Button> </StackPanel>

English original link: http://dontcodetired.com/blog/post/Using-MVVM-Light-in-Universal-Windows-Apps.aspx

Use MVVM light in the Windows Universal app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.