This section will be a little unusual.
For the record, I note that the entire review of the PRISM 4 is based on ebook'a Fri "Developers Guide to Microsoft Prism. MVVM and Building Modular Applications with WPF and Silverlight"
Part 4 deals with the most awaited my chapter, "Implementing the MVVM pattern" and " MVVM Advanced Scenarios" . Since in this part of the book, the author described the pattern MVVM assumptions, which are described in my earlier posts, I will use them for reference to the description of each department as part of the above chapters.
Implementing the pattern MVVM
Class Responsibilities and Characteristics
In this section you will find a description of the design pattern MVVM. If you are interested I refer to post "Official Healthy Diet - Standard MVVM - The concept of"
Class interactions
Part This report describes a binding mechanism and the interaction between the View and ViewModel'em using INotifyPropertyChanged interfaces, INotifyCollectionChanged, ICollectionView, Commanding, IDataError, INotifyDataErrorInfo.
The use of the first two interfaces can be found also in the post "Official Healthy Diet - Standard MVVM - The concept of" . Commandingu mechanism is presented in the post "Official Healthy Diet - Standard MVVM - Commanding"
Below I will present the opportunities offered to us and interface ICollectionView DelegateCommand who PRISM'ową interface ICommand implementation.
ICollectionView is an interface that allows us to sorting, filtering, grouping, and tracking of the currently selected item in the collection. This is very helpful from the point of view because we get quite MVVM rich functionality of operations on the collections side ViewModel.
PagedCollectionView is a class that in Silverlight (in WPF is a class ListCollectionView) implements the interface in question.
Below a brief example of how to use it (the implementation of DevPrototype )
SelectedDictionary public Dictionary {get; set;}
public ObservableCollection DictionariesCollection
{
get { return _dictionariesCollection; }
set
{
_dictionariesCollection = value;
Dictionaries = new PagedCollectionView(_dictionariesCollection);
Dictionaries.CurrentChanged += SelectedItemChanged;
NotifyOfPropertyChange(() => DictionariesCollection);
}
}
public ICollectionView Dictionaries
{
get { return _dictionaries; }
set
{
_dictionaries = value;
NotifyOfPropertyChange(() => Dictionaries);
}
}
private void SelectedItemChanged( object sender, EventArgs e )
{
SelectedDictionary = Dictionaries.CurrentItem as Dictionary;
}
private void OnGroupCommand(object obj)
{
Dictionaries.GroupDescriptions.Add(new PropertyGroupDescription("Description"));
}
private void OnUngroupCommand(object obj)
{
Dictionaries.GroupDescriptions.Clear();
}
private void OnSortCommand(object obj)
{
Dictionaries.SortDescriptions.Add(new SortDescription("Description",ListSortDirection.Ascending));
}
DelegateCommand implementuje interfejs ICommand (polecam post „Dziennik Healthy Diets - Standard MVVM - Commanding " and provide two things. The first is the ability to force re-check method CanExecute by RaiseCanExecuteChanged method (); The second thing is to link the values \u200b\u200bof the ISENABLED with the result of the method CanExecute . These two things perfectly complement in scenarios where for example we have validated the field and click "Save." Keep in mind that podpinając DelegateCommand the Button, we do not have the personal capacity zbindowania propercji ISENABLED. This class was also built for the controls that inherit from ButtonBase. People from the Prisma themselves in the book suggest that, for other controls, and other events worth looking into the SDK Behavior'om Blenda. Mostly they mean InvokeCommandAction and CallMethodAction . For details on these two Behavior'ów refer to post "Review of Action (Blend SDK) in the context MVVM part. 1 "
Construction and Wire-Up
This section describes the management starategie View and ViewModel. We are here for election:
- ViewModel First - first initialized is ViewModel, and then inside ViewModelu instancjonowana The form is View. Remember to keep in such ViewModelu bezparametrowy constructor in order to properly display our View in VS designer or Blend.
- First View - View is initialized first. Creating an instance ViewModelu can be done either in the XAML as well as in Loaded event. For details on this strategy, refer to post "Official Healthy Diet - Blendability MVVM"
and MessageBox PopUp
is a total of only original thing I've created a team for the PRISM MVVM pattern. A set of classes and interfaces IInteractionRequest, InteractionRequestTrigger, Confirmation and Notification is intended to help the programmer to create popup windows MessageBox type in such a way that the ViewModelu there was a direct appeal to such specific items are only available in Silverlight. This facilitates the testing, which trigger this type of components is carried out on an event. A simple example
var result = interactionService.ShowMessageBox (
"Are you sure you want to cancel this operation?"
"Confirm",
MessageBoxButton.OK);
if (result == MessageBoxResult.Yes)
{
CancelRequest ();}
ViewModel'uz Regarding the interaction of our UI logic, I refer to post "Official Healthy Diets - The logic of UI in MVVM" , where he presented his own idea of \u200b\u200bhow our ViewModel can operate with the logic available on the side view are not directly affiliated with this view.
0 comments:
Post a Comment