Your SlideShare is downloading. ×
0
Braintreehttp://www.nrumyantsev.com/
            2
3
4
Model                View            Controller5
Model                  View                           DataBinding            Presentation               Model            (...
7
8
<DataTemplate x:Key="MapTemplate">           <my:Pushpin Location="{Binding Location}" /></DataTemplate>...<my:Map Name="m...
          <StackPanel Orientation="Horizontal" Height="22">             <Label Width="50"> Options: </Label>           ...
public class SearchCommand : ICommand   {       private ViewModel viewModel;         public SearchCommand(ViewModel viewMo...
      http://unity.codeplex.com12   
     IUnityContainer Container = new UnityContainer();     if (ViewModelBase.IsInDesignModeStatic)     {             Cont...
14
15
               16
     <phone:PhoneApplicationPage       x:Class="MvvmLiteRTM.MainPage"       xmlns="http://schemas.microsoft.com/winfx/20...
     <Button Content=“ZoomIn" Height="72" Name=“ZoomInButton">        <i:Interaction.Triggers>             <i:EventTrigg...
         RelayCommand ZoomOutCommand = new RelayCommand(                 () =>                 {                        ...
View       View                          Messages       ViewModel     ViewModel                                       View...
         private void SendMessageWithCallback()         {            Messenger.Default.Send(new NotificationMessageActio...
private NotificationMessageAction<string> _lastMessage;     public void MessageRecipient()     {             Messenger.Def...
     http://ultralightmvvm.codeplex.com/     http://mvvmlight.codeplex.com/     http://catel.codeplex.com/     http://...
24
                                   25
                    26
View                   Feature     View Model               IFeature                  Injection27
28
29
     30
      http://create.msdn.com      http://silverlight.codeplex.com/      Model-View-ViewModel (MVVM) Explained      ...
Upcoming SlideShare
Loading in...5
×

Применение шаблона проектирования MVVM при разработке архитектуры Windows Phone 7 приложений

1,913

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,913
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • -Does not have a presenter, has a controller-Request first comes to controller, binds the model with the view-Logic is stored in controller
  • -State and Logic stored in Presenter-Presenter is an abstraction of view, Presenter unaware of view-View is aware of Presenter, however isolated from Model
  • -State and Logic stored in Presenter-Presenter is an abstraction of view, Presenter unaware of view-View is aware of Presenter, however isolated from Model-Uses WPF and Silverlight bindings-A very loose coupling between view and viewmodel, very easy to write unit tests-Growing in popularity (several toolkits MVVM Light, Prism, Caliburn)-Used internally at Microsoft during Expression Blend creation
  • -CanExecute determines if the command can be invoked on the current command target-Execute determines the command action to be performed-CanExecuteChanged event is raised when the command manager detects a change in the command source
  • -Uses the System.Windows.Interactivity namespace
  • -Avoid having to write separate class for commands, and implementing Icommand-lamba expression as an action
  • -allows you to send messages between view models-possible to open up filtered channels (to target types/interfaces)
  • -the sender sends a string message with a parameter of type NotificationMessageAction&lt;string&gt;-the callback parameter is a string
  • -The recipient registers to receive a message of type NotificationMessageAction-The Notification property of the NotificationMessageAction type contains the string message-The recipient executes the sender’s callback with a string parameter
  • -CheckBeginInvokeOnUI excepts Action parameter-Also contains UIThreadDispatrcher property in case you need to do other work on the UI thread.
  • Transcript of "Применение шаблона проектирования MVVM при разработке архитектуры Windows Phone 7 приложений"

    1. 1. Braintreehttp://www.nrumyantsev.com/
    2. 2.    2
    3. 3. 3
    4. 4. 4
    5. 5. Model View Controller5
    6. 6. Model View DataBinding Presentation Model (ViewModel)6
    7. 7. 7
    8. 8. 8
    9. 9. <DataTemplate x:Key="MapTemplate"> <my:Pushpin Location="{Binding Location}" /></DataTemplate>...<my:Map Name="map1" Height="494" HorizontalAlignment="Left" Margin="20,6,0,0" VerticalAlignment="Top" Width="444" Center="{Binding MapCenter, Mode=TwoWay}" ZoomLevel="{Binding MapZoomLevel, Mode=TwoWay}"> <my:MapItemsControl x:Name="ListOfItems" ItemTemplate="{StaticResource MapTemplate}" ItemsSource="{Binding LocationDataCollection}"> </my:MapItemsControl> </my:Map> 9
    10. 10.   <StackPanel Orientation="Horizontal" Height="22"> <Label Width="50"> Options: </Label> <Button x:Name="Search" Width="100" Command="{Binding SearchCommand}" >Search</Button> </StackPanel>10
    11. 11. public class SearchCommand : ICommand { private ViewModel viewModel; public SearchCommand(ViewModel viewModelInstance) { viewModel = viewModelInstance; } #region ICommand Members public bool CanExecute(object parameter) { return true; } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public void Execute(object parameter) { viewModel.Search(); } #endregion11 }
    12. 12.   http://unity.codeplex.com12 
    13. 13.  IUnityContainer Container = new UnityContainer(); if (ViewModelBase.IsInDesignModeStatic) { Container.RegisterType<IDataService,Design.DesignDataService>(); } else { Container.RegisterType<IDataService, DataService>(); } Container.RegisterType<MainViewModel> (new ContainerControlledLifetimeManager());13
    14. 14. 14
    15. 15. 15
    16. 16.    16
    17. 17.  <phone:PhoneApplicationPage x:Class="MvvmLiteRTM.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:vm="clr-namespace:MvvmLiteRTM.ViewModel" DataContext="{Binding Main, Source={StaticResource Locator}}" shell:SystemTray.IsVisible="True“>17
    18. 18.  <Button Content=“ZoomIn" Height="72" Name=“ZoomInButton"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <cmd:EventToCommand Command="{Binding ZoomInCommand}"/> </i:EventTrigger> </i:Interaction.Triggers> </Button>18
    19. 19.  RelayCommand ZoomOutCommand = new RelayCommand( () => { MapZoomLevel--; } ); 19
    20. 20. View View Messages ViewModel ViewModel View Messages + callback ViewModel20
    21. 21.  private void SendMessageWithCallback() { Messenger.Default.Send(new NotificationMessageAction<string>( "Hello, call me back", SendMessageCallback)); } private void SendMessageCallback(string message) { ... } 21
    22. 22. private NotificationMessageAction<string> _lastMessage; public void MessageRecipient() { Messenger.Default.Register<NotificationMessageAction<string>>( this, m => { MessageTextBox.Text = m.Notification; _lastMessage = m; // Execute callback with parameter _lastMessage.Execute(MessageTextBox.Text); }); }22
    23. 23.  http://ultralightmvvm.codeplex.com/ http://mvvmlight.codeplex.com/ http://catel.codeplex.com/ http://caliburnmicro.codeplex.com/23 http://www.japf.fr/silverlight/mvvm/index.html
    24. 24. 24
    25. 25.        25
    26. 26.     26
    27. 27. View Feature View Model IFeature Injection27
    28. 28. 28
    29. 29. 29
    30. 30.  30
    31. 31.   http://create.msdn.com  http://silverlight.codeplex.com/  Model-View-ViewModel (MVVM) Explained  WPF Apps With The Model-View-ViewModel Design Pattern - Josh Smith  http://nrumyantsev.com/  me@nrumyantsev.com31
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×