- 浏览: 36033 次
- 性别:
- 来自: 北京
文章分类
最新评论
A Contact Manager
Choosing an Architecture-interactive application
MVC-
Model objects represent the business concerns that are specific to the application being built;
Views are the actual visible components of an application;
Controllers traditionally functioned as mediators between the human and the application by handling user input from the mouse or keyboard(many of the responsibilities that the Controller had in the original
pattern have been taken over by WPF’s rich control set);
MVP-
Model/View/Presenter,evolved from MVC;(M-primary purpose is to represent business-specific constructs in software;Supervising-Controller pattern,Passive-View pattern)
Expander,allow the user to collapse or expand a named region of the interface,use the Header property to label the region.The Header property is of type object.(RotateTransform)
Slider,property-Minimum,Maximum,Interval, SmallChange, and LargeChange
TabControl,inherits from ItemsControl,most commonly used to display a collection of TabItem controls;
the TabControl can be scaled to the user’s preference via the data binding between the ScaleTransform and the Slider;
Aggregate
Notifier : INotifyPropertyChanged(which is property changed notification mechanism,enables more powerful data binding in WPF.)
Address : Notifier
//notifier.cs using System; using System.ComponentModel; namespace ContactManager { [Serializable] public abstract class Notifier : INotifyPropertyChanged { [field: NonSerialized] public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged( this, new PropertyChangedEventArgs(propertyName) ); } } } } //address.cs using System; namespace ContactManager.Model { [Serializable] public class Address : Notifier { private string _city; private string _country; private string _line1; private string _line2; private string _state; private string _zip; public string City { get { return _city; } set { _city = value; OnPropertyChanged("City"); } } public string Country { get { return _country; } set { _country = value; OnPropertyChanged("Country"); } } public string Line1 { get { return _line1; } set { _line1 = value; OnPropertyChanged("Line1"); } } public string Line2 { get { return _line2; } set { _line2 = value; OnPropertyChanged("Line2"); } } public string State { get { return _state; } set { _state = value; OnPropertyChanged("State"); } } public string Zip { get { return _zip; } set { _zip = value; OnPropertyChanged("Zip"); } } } } //states.cs using System.Collections.Generic; namespace ContactManager.Model { public static class States { private static readonly List<string> _names; static States() { _names = new List<string>(50); _names.Add("Alabama"); _names.Add("Alaska"); _names.Add("Arizona"); _names.Add("Arkansas"); _names.Add("California"); _names.Add("Colorado"); _names.Add("Connecticut"); _names.Add("Delaware"); _names.Add("Florida"); _names.Add("Georgia"); _names.Add("Hawaii"); _names.Add("Idaho"); _names.Add("Illinois"); _names.Add("Indiana"); _names.Add("Iowa"); _names.Add("Kansas"); _names.Add("Kentucky"); _names.Add("Louisiana"); _names.Add("Maine"); _names.Add("Maryland"); _names.Add("Massachusetts"); _names.Add("Michigan"); _names.Add("Minnesota"); _names.Add("Mississippi"); _names.Add("Missouri"); _names.Add("Montana"); _names.Add("Nebraska"); _names.Add("Nevada"); _names.Add("New Hampshire"); _names.Add("New Jersey"); _names.Add("New Mexico"); _names.Add("New York"); _names.Add("North Carolina"); _names.Add("North Dakota"); _names.Add("Ohio"); _names.Add("Oklahoma"); _names.Add("Oregon"); _names.Add("Pennsylvania"); _names.Add("Rhode Island"); _names.Add("South Carolina"); _names.Add("South Dakota"); _names.Add("Tennessee"); _names.Add("Texas"); _names.Add("Utah"); _names.Add("Vermont"); _names.Add("Virginia"); _names.Add("Washington"); _names.Add("West Virginia"); _names.Add("Wisconsin"); _names.Add("Wyoming"); } public static IList<string> GetNames() { return _names; } } }
Abstract Data Store
Regardless of what the underlying data store is, every well-architected solution hides this technicality from the rest of the application.
A common pattern is to execute all datarelated activity through a repository class(Separation of Concerns (SoC)-The important part of a repository is that it abstracts away the actual data store so that other parts of the application are able to work with a high-level API and not concern themselves with how the data is stored.);
//ContactRepository.cs using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; namespace ContactManager.Model { public class ContactRepository { private List<Contact> _contactStore; private readonly string _stateFile; public ContactRepository() { _stateFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"ContactManager.state"); Deserialize(); } public void Save(Contact contact) { if (contact.Id == Guid.Empty) contact.Id = Guid.NewGuid(); if (!_contactStore.Contains(contact)) _contactStore.Add(contact); Serialize(); } public void Delete(Contact contact) { _contactStore.Remove(contact); Serialize(); } public List<Contact> FindByLookup(string lookupName) { IEnumerable<Contact> found = from c in _contactStore where c.LookupName.StartsWith( lookupName, StringComparison.OrdinalIgnoreCase) select c; return found.ToList(); } public List<Contact> FindAll() { return new List<Contact>(_contactStore); } private void Serialize() { using (FileStream stream =File.Open(_stateFile, FileMode.OpenOrCreate)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, _contactStore); } } private void Deserialize() { if (File.Exists(_stateFile)) { using (FileStream stream =File.Open(_stateFile, FileMode.Open)) { BinaryFormatter formatter = new BinaryFormatter(); _contactStore =(List<Contact>)formatter.Deserialize(stream); } } else _contactStore = new List<Contact>(); } } }
a repository, is a type of class that hides the actual data storage mechanism from the rest of the application. It embodies SoC by separating any datarelated code from other classes and encapsulating it in a way that hides the internal complexity from unconcerned parties.
小结:
wpf,is real power.
发表评论
-
wpf应用实例
2010-07-24 15:45 1065使用WPF快速创建可拖拽的对象和窗体。 -
业务流的前端,intel终极理想:感应终端环境与任意平面成屏技术
2010-07-08 12:44 1022在欧美等人力成本高 ... -
wpf 研习1-24小时自学wpf16
2010-06-15 23:21 1382Visualizing Lists-displaying mo ... -
wpf 研习1-24小时自学wpf15
2010-06-14 23:25 936deeper into data binding ad ... -
wpf 研习1-24小时自学wpf14
2010-06-13 10:27 1400Resources and Styles 从下图,我们 ... -
wpf 研习1-24小时自学wpf13
2010-06-11 23:04 910Presenters and Views-the Shell ... -
wpf 研习1-24小时自学wpf11
2010-06-10 15:02 969output WPF Document Con ... -
了解WPF中的路由事件和命令
2010-06-09 23:12 1332路由事件浏览 (1)在vs designer中,如在窗口中增 ... -
wpf 研习1-24小时自学wpf10
2010-06-09 16:25 976Commands In WPF, a command is ... -
wpf 研习1-24小时自学wpf9
2010-06-08 19:19 773events handle routed event: ... -
wpf 研习1-24小时自学wpf8
2010-06-07 16:10 886A real-world program basic ... -
wpf 研习1-24小时自学wpf7
2010-06-07 11:04 846Application deployable file ... -
wpf 研习1-24小时自学wpf6
2010-06-05 17:14 873Data Binding markup extensi ... -
wpf 研习1-24小时自学wpf5
2010-06-05 16:14 1064basic Control Control base ... -
wpf 研习1-24小时自学wpf4
2010-06-05 11:31 666Layout Panel,Decorator; Sy ... -
wpf 研习1-24小时自学wpf3
2010-06-04 19:11 812wpf项目文件 vs->新项目->wpf应用程序 ... -
wpf 研习1-24小时自学wpf2
2010-06-04 15:39 829XAML,既然用户控件是一个大类,那么干脆对这个集合进行统一的 ... -
wpf 研习1-24小时自学wpf1
2010-06-04 12:05 727WPF是微软.net的UI 架构,也是非常重要的框架。 ... -
wpf主要知识点
2010-06-04 10:47 982template,presenter,layout,visua ... -
路由事件
2010-05-17 22:09 648如果我们在一个窗口上增加一个按钮,并且看下它的后置代码,会发现 ...
相关推荐
本文将围绕“wpf 研习1-24小时自学wpf6”这一主题,探讨WPF的核心概念和技术,旨在帮助初学者快速上手并深入理解这一强大的UI框架。 WPF是微软.NET Framework的一部分,它提供了全面的图形系统,包括2D和3D渲染、...
【标题】:“WPF研习1-24小时自学WPF9” 在Windows Presentation Foundation(WPF)的世界里,这是一段深入学习之旅的开端。WPF是.NET Framework的一个重要组成部分,它为创建丰富的、高性能的桌面应用程序提供了...
标题 "wpf 研习1-24小时自学wpf7" 提示我们这是一个关于Windows Presentation Foundation(WPF)的学习资源,可能是书籍、课程或教程的一部分,旨在帮助初学者在24小时内掌握WPF的基础知识。WPF是.NET Framework中的...
【标题】:“wpf 研习1-24小时自学wpf8”是指一系列针对Windows Presentation Foundation(WPF)框架的学习教程,旨在帮助初学者在24小时内掌握WPF的基础知识和应用技巧。WPF是.NET Framework的一部分,用于构建...
NULL 博文链接:https://x-dome.iteye.com/blog/684355
对于想要开发Windows应用的学员,WinForms和WPF(Windows Presentation Foundation)的使用也会有所介绍。 在幻灯片部分,可能会包含每章节的重点摘要,清晰的示例图解,以及关键概念的解释,帮助学生更好地吸收和...