Skip to content

Instantly share code, notes, and snippets.

@jcbozonier
Created February 17, 2009 00:01
Show Gist options
  • Select an option

  • Save jcbozonier/65478 to your computer and use it in GitHub Desktop.

Select an option

Save jcbozonier/65478 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using FantasyNewApp.Models;
using FantasyNewApp.Utilities;
namespace FantasyNewApp.ViewModels
{
public class PersonViewModel : INotifyPropertyChanged
{
private Person _MyPerson;
public Click_Command Clicky { get; set; }
public string FirstName
{
get
{
return _MyPerson.FirstName;
}
set
{
_MyPerson.FirstName = value;
}
}
public string MiddleName
{
get
{
return _MyPerson.MiddleName;
}
set
{
_MyPerson.MiddleName = value;
}
}
public string LastName
{
get
{
return _MyPerson.LastName;
}
set
{
_MyPerson.LastName = value;
}
}
public string DisplayName
{
get
{
return _MyPerson.DisplayName;
}
}
public PersonViewModel()
{
var person = new Person()
{
FirstName = "Justin",
MiddleName = "Charles",
LastName = "Bozonier"
};
_MyPerson = person;
var context = new BindingContext(_MyPerson, () => PropertyChanged);
//It'd be nice to remove the redundant contexts
context
.Bind(() => FirstName)
.From(()=> _MyPerson.FirstName)
.OnChangeDo((s,e)=>Clicky.RaiseCanExecuteChanged());
context
.Bind(() => MiddleName)
.From(() => _MyPerson.MiddleName)
.OnChangeDo((s, e) => Clicky.RaiseCanExecuteChanged());
context
.Bind(() => LastName)
.From(() => _MyPerson.LastName)
.OnChangeDo((s, e) => Clicky.RaiseCanExecuteChanged());
context
.Bind(() => DisplayName)
.From(() => _MyPerson.DisplayName)
.OnChangeDo((s, e) => Clicky.RaiseCanExecuteChanged());
Clicky = new Click_Command();
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment