I have a WPF application that is designed to retrieve information asynchronously from a database, and when it finally retrieved it, display it in various text fields.
My asynchronous search works fine, but I'm new to WPF and MVVM. Previously, I didn’t have the proper separation of my interface and my model, and therefore it was easy to tell the text fields to display “Querying ...” until the actual data was available.
Now, although I tried to separate the model from the user interface, and I'm not sure where to put it.
Is it permissible (from the point of view of MVVM) that the user interface button update various text fields of the user interface in order to say “Querying ...” inside its own click event (along with calling the ViewModel method, which will ultimately update the properties, these text fields associated with, which then should replace them with actual data)?
If not, then somewhere ... this logic is coming. (I also know Teams are better than onClick events, but please, one thing at a time :))
Here's what I'm looking at right now:
class MainWindow
{
private ViewModel _viewModel;
doStuffButton_Click(object sender, RoutedEventArgs e)
{
textBox1.Text = "Querying..."
textBox2.Text = "Querying..."
_viewModel.asyncGoAndLookupStuff();
}
}
? , ViewModel? , ViewModel , ( ) . ValueConverter ( )? , , .
, , ViewModel, , ViewModel , , , -.
EDIT:
, , . - ( /)
class DataItem
{
public int SmallNumber { get; private set; }
public int BigNumber { get; private set;}
}
class Model
{
public DataItem Foo;
public DataItem Bar;
}
( ) , ViewModel.Model.Foo.SmallNumber ViewModel.Model.Bar.BigNumber.
ViewModel (, ViewModel.FooSmallNumber ), ? , , , . ( , , , ... , , .)