Project Description
Dynamic MVVM enables you to quickly build a functional MVVM application, based on WPF without ICommand and XAML and viewmodel Validation.


**Quick start **

The DynamicMVVM is a set of classes which help developer to get started in the Model - View - ViewModel pattern WPF (not supported on Silverlight). It is a small framework that contains only Dynamic ViewModel and Dynamic Model.
The DynamicViewModel Allows developer to create the Command’s Execute method and CanExecute method without the ICommand property.
e.g. In standard fashion way your ViewModel as below

public class PersonDetailsViewModel : INotifyPropertyChanged
{
public ICommand SaveCommand { get; set; }
public ICommand CancelCommand { get; set; }

public PersonDetailsViewModel()
{
Model = new PersonModel{
Id = 1,
FName = "Abc",
LName = "Xyz",
Dob = new DateTime(2011, 1, 1),
Active = true,
Salary = 12345
};

SaveCommand = new RelayCommand((object obj) =>
{
//your code...
}, (object obj) => Model.IsDirty);
CancelCommand = new RelayCommand((object obj) =>
{
//your code...
}, (object obj) => Model.IsDirty);
}
public PersonModel Model { get; set; }
... your rest of code
}

Instead of above demonstrated code, you can write as below code with the DynamicMVVM

public class PersonDetailsViewModel : DynamicViewModel
{
public PersonDetailsViewModel()
{
Model = new PersonModel{
Id = 1,
FName = "Abc",
LName = "Xyz",
Dob = new DateTime(2011, 1, 1),
Active = true,
Salary = 12345
};
}
public PersonModel Model { get; set; }

public bool CanExecuteCancel(object o)
{
return Model.IsDirty;
}
public void ExecuteCancel(object o)
{
;;//your code...
}
public bool CanExecuteSave(object o)
{
return Model.IsDirty; ;//your code...
}
public void ExecuteSave(object o)
{
;//your code...
}
}

The DynamicModel Allows developer to create the model without INotifyPropertyChanged implementation and the medal’s properties without PropertyChanged
Event and it’s allows developer to add DataAnnotations’s attributes to add validation.
e.g. Model example as below
public class Person
{
[Display(Name = "Employee Id")]
[Required]
public int Id { get; set; }

[Display(Name = "First Name")]
[Required]
[StringLength(25)]
public string FName { get; set; }

[Display(Name = "SurName")]
[Required]
[StringLength(25)]
public string LName { get; set; }

public DateTime Dob { get; set; }

[Display(Name = "Salary PM")]
[Required]
public decimal Salary { get; set; }

public bool Active { get; set; }
}
Then pass the Person Model into DynamicModel as below
Model = new DynamicMVVM.DynamicModel(new Person
{
Id = 1,
FName = "Abc",
LName = "Xyz",
Dob = new DateTime(2011, 1, 1),
Active = true,
Salary = 12345

}

Last edited Mar 4, 2012 at 6:31 PM by hasmukhlalpatel, version 5