Universal application in Windows MVVM

I just started to develop in a universal application. I developed the application in applications for storing Windows 8, and also developed applications for Windows Phone 8 and Windows Phone 8.1 (SilverLight). The question is related to the universal application in Windows and the single user interface that is created in the application. Share folder.

1. I am new to MVVM . I normally developed Windows 8 and WP8.1. But not with MVVM. I searched a lot, but did not get any example that could better understand MVVM. I know what MVVM is. This is similar to MVC Asp.net.

MVVM -

Model : what data is described

View-Model . A simple word is the bridge between Model and View.

View : a simple page or xaml user interface.

Which is better or better way to make code in Windows Phone 8 MVVM or Normal?

The usual way means without using MVVM.

Link: Separate the logic of the user interface and application using the Model-View-ViewModel template.

+4
source share
2 answers

This is a broad question to answer in one post. I will provide a couple of things to think and explore.

(Note: all of the code in this post is a free hand from memory. It may not be 100% syntactically correct.)

, , MVVM. MVVM MVC , View to View Model (Controller). , .

, WP 7, WP 8, WP8.1, Siverlight Universal App. WPF, MVVM , , .

.

1) "Views" "ViewModels". , .

2) TextBlock. xaml . "" "MyFirstPage". :

<TextBlock Text="The Title of my App" />

3) , .

4) ViewModel. . ViewModels MyFirstViewModel.

5) () ViewModel. , , . DataContext - . , , , . , , .

public class MyFirstPage : Page
{
    private MyFirstViewModel _viewModel = new MyFirstViewModel();

    public MyFirstPage()
    {
        this.Initialize???
        this.DataContext = _viewModel;
    }

6) Title .

public string Title { get { return "The Title of my App (set from View Model)"; } }

7) TextBlock

<TextBlock Text="{Binding Title}" />

8) , , .

, .

, :

  • . , TextBox, , {Binding FirstName, Mode = TwoWay} , .

  • . , , , . , , , . . , . , , FirstName, INotifyPropertyChanged ViewModel OnPropertyChanged ( "FirstName" ). , .

  • ObservableCollections. , , , , . - ObservableCollection. , . , , getter . , getter . - ObservableCollection, , OnPropertyChanged , , ObservableCollection, . , , . .

  • . , , . BooleanToVisibilityConverter. . , .

  • . , , . relay click. , , , ViewModel, , , Button RelayCommand .

, .

, , , .

: ViewModel , - ( ). , , . , , Lib ViewModels . Windows Phone 8.1 Project, Windows 8.1 (Store) Lib. ViewModels Lib , . , , , Inversion of Control, .

,

Tom

+12

Nico Vermeir MVVM Light http://www.spikie.be/blog/post/2014/06/30/.aspx

stackO, URL-:)

+1

Source: https://habr.com/ru/post/1568841/


All Articles