Quick Start

1. Create a new View Model that exposes ViewModelTop in Sovacode.RubiksCube.Common.ViewModel namespace:

/* Importing namespaces */
using Sovacode.RubiksCube.Common.ViewModel;

public class MyViewModel : ViewModelTop /* base view model class */
{

}

2. After you can override two methods RegisterCommands() and RegisterValidationRules(). The RegisterCommands() will register your commands and RegisterValidationRules() will register your validation rules.
public class MyViewModel : ViewModelTop 
{
        private string _name = string.Empty;

        /// <summary>
        /// Simple Property
        /// </summary>
        public string Name {
        get { return _name; }
        set 
        { 
             _name = value;
            /* Notifity listeners */
            OnPropertyChanged(() => Name);
         }

         /* Some method */
         private void SomeCommand() { /* TODO */ }

         protected override void RegisterCommands()
         {
             base.RegisterCommands();

             RegisterCommand("SomeCommand", o => SomeCommand());
         }

         protected override void RegisterValidationRules()
         {
             /* That's all. Now Property Name will be validated. */
             RegisterRule(() => Name, () => !string.IsNullOrWhiteSpace(Name), "Name can not be empty!");
          }
}

3. Now you can setup your XAML. To bind your commands you need to add [ and ] in binding parameter:

<TextBox VerticalContentAlignment="Center" Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Height="23" Margin="5,0,5,5"/>

<Button Command="{Binding [SomeCommand]}" Content="Something" Height="23" Margin="5,0"/>

On-line API Documentation

Last edited Apr 4, 2013 at 8:49 PM by Daniil_Monin, version 3

Comments

No comments yet.