I can't really wrap my head around the following problem:
All I have in the application is a textbox
for the user input, a button
for performing a background calculation on that input and a textblock
. Imagine I have to use MVVM, so I have my view
, viewmodel
and model
classes.
I bind the controls (textbox
, button
and textblock
) from the view to the viewmodel
on corresponding properties and commands. However, I'm not sure where the viewmodel
functionality should end. For instance, would the following be a way to structure the application?
Model:
public class Model
{
public string Input { get; set; }
public string Output { get; set; }
public void FancyMethod ()
{
// Use input to calculate output
}
}
ViewModel:
public class ViewModel
{
public string Input {get; set;}
public string Output {get; set;}
public ICommand command {get; set;}
public Model model {get; set;}
public ViewModel()
{
model = new Model();
}
// When the button is pressed, model.input = Input and then execute model.FancyMethod()
}