Mvvm ViewModel Model

Can it be called an MVVM model or not? Because View interacts with DataModel through ViewModelData. Should View only interact with ViewModelData? I read somewhere that the correct MVVM model should implement INotify in the ViewModel, not the model. Correctly?

namespace WpfApplication135
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

    public MainWindow()
    {
        InitializeComponent();
        DataContext = new ViewModelData();
    }
}
public class ViewModelData
{
    public DataModel DM { get; set; }
    public ViewModelData()
    {
        DM = new DataModel();
    }
}
public class DataModel : INotifyPropertyChanged
{
    public int label;
    public int Label
    {
        get
        {
            return label;
        }

        set
        {
            label = value;
            RaisePropertyChanged("Label");
        }
    }
    public DataModel()
    {
        Action Update = new Action(Run);
        IAsyncResult result = Update.BeginInvoke(null, null);
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string info)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(info));
    }
    public void Run()
    {
        int i=0;
        while(true)
        {
            System.Threading.Thread.Sleep(2000);
            Label = ++i;
        }
    }
}
}

Xaml

    <Grid>
    <Label Content="{Binding DM.Label}" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>

</Grid>
+4
source share
2 answers

The initial thought of MVVM was that the view should not know (independent of) the Model.

ViewModel (. - ), . , INPC, , . Entity Framework INPC T4.

, ViewModel.Model , DM. . - .

, . , .

WPF LOB Apllication Layers - MVVM

+10

MVVM , . ViewModel. , ViewModel - . .

, MVVM , Q & A .

0

All Articles