- WPF Desktop Application
- MVVM Architecture Pattern
- Observer Pattern
- Factory Pattern
- Command Pattern
- Dependency Injection Pattern
- Event Aggregator Pattern
- Façade Pattern
- Inversion of Control Pattern
- Repository Pattern
Windows Presentation Foundation (WPF) is a UI framework that creates desktop client applications. The WPF development platform supports a broad set of application development features, including an application model, resources, controls, graphics, layout, data binding, documents, and security.
MVVM Architecture Pattern:
MVVM hỗ trợ cơ chế two-way binding giữa View và ViewModel. Điều này cho phép tự động đồng bộ các thay đổi giữa 2 thành phần. Nhìn chung, ViewModel tối ưu sử dụng pattern Observer để thông báo sự thay đổi trong ViewModel sang Model.
Model bao gồm một tập hợp các class mô tả nghiệp vụ của ứng dụng, các đối tượng làm việc trong ứng dụng và các class truy cập dữ liệu. Nó cũng định nghĩa các quy tắc nghiệp vụ để dữ liệu có thể được sửa và thao tác ra sao.
View hiển thị các thành phần giao diện người dùng như CSS, jQuery hay HTML…View hiển thị dữ liệu được nhận về từ controller như là đầu ra. Đây cũng là nơi thay đổi dữ liệu của Model do người dùng nhập vào.
ViewModel có trách nhiệm hiển thị các phương thức, các sự kiện và các hàm khác giúp cho việc bảo đảm trạng thái của View, việc thao tác trên Model là kết quả của các hành động trên View, và kích hoạt các sự kiện trên chính View.
EBook: Applied WPF 4 in Context.pdf
Patterns in the Prism Library for WPF
Introduction of MVVM
MVVM is an abbreviation of a design pattern named Model-View-ViewModel which originated from Microsoft. It is a specialization of Presentation Model introduced by Martin Fowler, a variant of the famous MVC pattern. This pattern has 3 roles: View, Model, and ViewModel. The View and Model plays the same roles as they do in MVC.
The ViewModel in MVVM acts like a special Controller for the View which is responsible for exposing data from the Model to the View and for providing required action and logic for user requests from the View. The ViewModel is type of View abstraction, which contains a View's state and behavior. But ViewModel should contain no reference to UI components and knows nothing about View's visual elements. Hence there is a clear separation between View and ViewModel, this is also the key characteristics of MVVM pattern. From another angle, it can also be said that the View layer is like an UI projection of the ViewModel.
Strength of MVVM
Separation of data and logic from presentation
The key feature is that ViewModel knows nothing about View's visual elements guarantees the one way dependency from View to the ViewModel thus avoiding mutual programming ripple effects between UI and the ViewModel. Consequently, it brings the following advantages:
- It's suitable for design-by-contract programming.  As long as the contract is made (what data to show and what actions to perform), the UI design and coding of ViewModel can proceed in parallel and independently. Either side will not block the other's way.
- Loose coupling with View. UI design can be easily changed from time to time without modifying the ViewModel as long as the contract does not change.
- Better reusability. It will be easier to design different views for different devices with a common ViewModel. For a desktop browser with a bigger screen, more information can be shown on one page; while for a smart phone with limited display space, designing a wizard-based step-by-step operation UI can be done without the need to change (much of) the ViewModel.
- Better testability. Since ViewModel does not "see" the presentation layer, developers can unit-test the ViewModel class easily without UI elements.
MVVM & ZK Bind
Since the ViewModel contains no reference to UI components, it needs a mechanism to synchronize data between the View and ViewModel. Additionally, this mechanism has to accept the user request from the View layer and bridge the request to the action and logic provided by the ViewModel layer. This mechanism, the kernel part of the MVVM design pattern, is either data synchronising codes written by the application developers themselves or a data binding system provided by the framework. ZK 6 provides a data binding mechanism called ZK Bind to be the infrastructure of the MVVM design pattern and the binder plays the key role to operate the whole mechanism. The binder is like a broker and responsible for communication between View and ViewModel.
Detail Operation Flow
Here we use a simple scenario to explain how MVVM works in ZK. Assume that a user click a button then "Hello World" text appears. The flow is as follows:
As stated in the paragraph earlier, the binder synchronizes data between UI and ViewModel.
- A user presses a button on the screen (perform an action).
- A corresponding event is fired to the binder.
- The binder finds the corresponding action logic (It is Command) in the ViewModel and executes it.
- The action logic accesses data from Model layer and updates ViewModel's corresponding properties.
- ViewModel notify the binder that some properties have been changed.
- Per what properties have been changed, the binder loads data from the ViewModel.
- Binder then updates the corresponding UI components to provide visual feedback to the user.
- WPF Apps With The Model-View-ViewModel Design Pattern http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
- Introduction to Model/View/ViewModel pattern for building WPF apps http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx
- Presentation Model http://martinfowler.com/eaaDev/PresentationModel.html
- Design by contract http://en.wikipedia.org/wiki/Design_by_contract
- Binder ZK Developer's Reference/MVVM/DataBinding/Binder
- Windows Presentation Foundation (WPF)
- Composite View design pattern
- Presentation Model pattern
- Supervising Controller Pattern
- Event Aggregator pattern
- Event-based Asynchronous Pattern
- IAsyncResult pattern
- Publish/Subscribe pattern
- Model-View-Presenter (MVP) pattern
- Model-View-ViewModel (MVVM) pattern
Solution Architecture for a WPF Application
- Patterns - WPF Apps With The Model-View-ViewModel Design Pattern
- Patterns For Building Composite Applications With WPF
Asynchronous Programming Model (APM) | Microsoft Docs (IAsyncResult pattern)
WinForms - @manhng (Windows Forms Application)
Welcome - The complete WPF tutorial (wpf-tutorial.com) (tài liệu tiếng Anh | Việt)
Window và XAML trong lập trình WPF | How Kteam (tài liệu tiếng Việt)
- DataGrid (DataGrid site:wpf-tutorial.com)
- TreeView (TreeView site:wpf-tutorial.com)
- Report (Report site:wpf-tutorial.com)
- Connection (Connection site:wpf-tutorial.com)
- Menu (Menu site:wpf-tutorial.com)
- Multi-threading with the BackgroundWorker (BackgroundWorker site:wpf-tutorial.com)
- Handling exceptions (Handling exceptions site:wpf-tutorial.com)
Using WPF commands
Using the Grid: A contact form
Using the Grid: ColumnDefinition and RowDefinition
Grid trong lập trình WPF | How Kteam (HAY HAY HAY)
+ Grid & ColumnDefinition & RowDefinition & ColumnSpan and RowSpan
+ Grid & GridSplitter & HorizontalAlignment
+ Grid & GridSplitter & VerticalAlignment
+ Grid & ScrollViewer & StackPanel
+ Thằng nào ra sau thì nằm trên (ghi đè)