Click here to Skip to main content
15,897,891 members
Articles
(untagged)

User Interface Patterns

Rate me:
Please Sign up or sign in to vote.
4.94/5 (21 votes)
18 Jun 2013CPOL7 min read 51.9K   413   55  
A brief overview of common user interface patterns, and some ideas about them.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions