This is a mirror of official site: http://jasper-net.blogspot.com/

MVVMLight Hello World in 10 Minutes.

| Wednesday, February 1, 2012
Getting Started

    Firstly, start VS2010, and create a new WPF project.
    Ensure that you have Nuget installed.
    Manage Nuget Package References and add ‘MVVM Light’

MVVM Light has now added a ViewModel folder containing the MainViewModel and the ViewModelLocator.
Edit the Main Window

Simply add a button, and defer the DataContext binding to the ViewModelLocator (elided):


<Window x:Class="MvvmLightTest.MainWindow"
        DataContext="{Binding Main, Source={StaticResource Locator}}">
    <Grid>
        <Button Command="{Binding ShowPopUp}" Content="Show Pop Up" />
    </Grid>
</Window>

Then in the MainViewModel we define the ShowPopUp command:


public class MainViewModel : ViewModelBase
{
    public MainViewModel()
    {
        ShowPopUp = new RelayCommand(() => ShowPopUpExecute(), () => true);
    }

    public ICommand ShowPopUp { get; private set; }

    private void ShowPopUpExecute()
    {
        MessageBox.Show("Hello!");
    }
}

Read more: Codeproject
QR: MVVMLight-Hello-World-in-10-Minutes

Posted via email from Jasper-net

0 comments: