-
Notifications
You must be signed in to change notification settings - Fork 121
Knockout Binding
David Desmaisons edited this page Sep 27, 2016
·
9 revisions
Given the following ViewModel:
public class Skill
{
public string Type { get;}
public string Name { get;}
public Skill (string name, string skillType)
{
Name = name;
Type = skillType;
}
}
public class Person: ViewModelBase
{
private string _LastName;
public string LastName
{
get { return _LastName; }
set { Set(ref _LastName, value, "LastName"); }
}
private string _Name;
public string Name
{
get { return _Name; }
set { Set(ref _Name, value, "Name"); }
}
private Skill _MainSkill;
public Skill MainSkill
{
get { return _MainSkill; }
set { Set(ref _MainSkill, value, "MainSkill"); }
}
public IList<Skill> Skills { get; private set; }
public ICommand RemoveSkill { get; private set; }
public Person()
{
Skills = new ObservableCollection<Skill>();
RemoveSkill = new RelayCommand<Skill>(s=> this.Skills.Remove(s));
}
}
<span data-bind="text:Name"><\span>
<span data-bind="Skill().Name"><\span>
<div data-bind="foreach: Skills">
<div ><span data-bind="text:Type"></span></div >
</div>