K
K
Konstantin Mosalev2018-07-11 01:26:09
WPF
Konstantin Mosalev, 2018-07-11 01:26:09

How to forward parameters in MVVM?

Good afternoon.
Could you tell me how to do parameter forwarding in the MVVM pattern using WPF.
The essence of the application is as follows:
View:
Has 1 field TextBlock displaying int.
ViewModel:
Collects from 2 Models by 1 parameter and adds them up.
Model(2 similar):
Using the DispatcherTimer, it calculates the parameter once per second (in a real application it takes the signal level from the router) and puts it in a variable, but for example, let the Model have 1 variable Count = 0 and add 1 every second.
And in ViewModel and Model implement the InotifyPropertyChanged interface.
But I can't get the value from the Model to the View

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LiptonOlolo, 2018-07-11
@LiptonOlolo

If I correctly understood the essence of the question, then:
VM:
view:
<TextBlock Text="{Binding Number}"/>

K
Konstantin Mosalev, 2018-07-11
@KonstMosalev

Model

public class Param : BaseNotify // реализует INotifyPropertyChanged
{
 int count = 0;
public int Count { get =>count; set { count = value; OnPropChanged("Count"); } }
public Param()
{
Met();
}
public void Met()
{
 while(true)
{
Count++;
}
}
}

VM
public class ViewModel : BaseNotify
{
int sum;
public int Sum { get =>sum; set { sum = value; OnPropChanged("Sum"); } }
public ViewModel()
{
 sum = Count;
}
}

View Is it possible to transmit in such a scheme? As described here does not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question