Answer the question
In order to leave comments, you need to log in
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
If I correctly understood the essence of the question, then:
VM:
view:<TextBlock Text="{Binding Number}"/>
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++;
}
}
}
public class ViewModel : BaseNotify
{
int sum;
public int Sum { get =>sum; set { sum = value; OnPropChanged("Sum"); } }
public ViewModel()
{
sum = Count;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question