Where in the code and how should I specify a text field to display a temporary downloadable message when using MVVM?

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..."
         // ... and so on in a foreach looop probably.

         _viewModel.asyncGoAndLookupStuff(); // starts a Task that
         // updates properties that the textBoxes are bound to
         // and fires the appropriate PropertyChanged events.
     }
}

? , ViewModel? , ViewModel , ( ) . ValueConverter ( )? , , .

, , ViewModel, , ViewModel , , , -.

EDIT:

, , . - ( /)

class DataItem
{
    // assume a ctor to set it up here.
    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 ), ? , , , . ( , , , ... , , .)

+3
3

.

Item1 ( ) VM, "Querying..." . Async , Dispatcher.Invoke( ThreadingContext), .

+1

. . :

string . async .

BusyControl Busy , .

, MVVM , . : " ( , ..), ? " ", .

+2

, Text :
<TextBox Text="{Binding MyProperty, TargetNullValue="Querying...", FallbackValue="Querying..."}" />

If you need text to return to the "Query ..." on the next query, set the text box style in all the affected text blocks using a trigger that sets the text as soon as some logical (IsQuerying) in your virtual machine is set to true. This will overwrite your binding if it is not set to TwoWay (and even then I'm not sure ...), so maybe setting another property is the way to go (e.g. IsEnabled or Opacity).

    <Style x:Key="QueryingStyle" TargetType="{x:Type TextBox}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding ElementName = ThisVrEditorView, Path=DataContext.IsQuerying}">
                <Setter Property="Text" Value="Querying..."/>   
                <Setter Property="IsEnabled" Value="False"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
+2
source

All Articles