|
using System.Windows;
using ActiveMVC.Controllers;
using ActiveMVC.MVC;
using ActiveMVC.Models;
namespace ActiveMVC.Views
{
public class PeopleTableView : View
{
public CtrlPeople Control { get; private set; }
public PeopleTableView(People model)
: base(model)
{
Control = new CtrlPeople();
}
protected override Controller GetController(string viewName)
{
return new PeopleTableController(this);
}
protected override void DisplayWindow(string viewName)
{
// Real MVC suggests a controller for each view so a button can be
// considered a view with its own controller. Some implementation
// let one controller handle all events of a view.
// Since in Windows, UI is source of all events, I placed routing
// calls here. In facr controller should do this or better yet,
// every view element has its own controller.
Control.LbxPeople.SelectionChanged +=
(sender, args) =>
Controller.HandleEvent(new ViewEvent {Name = "PersonSelected", Args = Control.LbxPeople.SelectedItem});
Control.Visibility = Visibility.Visible;
}
protected override void OnModelChanged(object args)
{
var people = Model as People;
if (people == null) return;
var change = args as string;
if (string.Equals(change, "People"))
{
ReloadPeople(people);
}
else if (string.Equals(change, "Selected"))
{
Control.LbxPeople.SelectedItem = people.Selected;
}
}
private void ReloadPeople(People people)
{
lock (people.All)
{
Control.LbxPeople.Items.Clear();
foreach (var person in people.All)
{
Control.LbxPeople.Items.Add(person);
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.