Update UI from ViewModel class (MVVM pattern) in WPF

后端 未结 6 1369
-上瘾入骨i
-上瘾入骨i 2020-12-29 12:59

I\'m using the MVVM pattern in my first WPF app and have a problem with something quite basic I assume.

When the user hits the \"save\" button on my view, a command

6条回答
  •  太阳男子
    2020-12-29 13:45

    You can accomplish this by the following code..

    Thread workerThread = null;
    void Save(object sender, ExecutedRoutedEventArgs e)
    {
    workerThread = new Thread(new ThreadStart(doWork));
    SaveButton.isEnable = false;
    workerThread.start();
    }
    

    do all your lengthy process in dowork() method

    in some other method...

    workerThread.join();
    SaveButtton.isEnable = true;
    

    This will cause to run save lengthy process in another thread and will not block your UI, if you want to show an animation while user click on save button then show some progress bar like iPhone etc... give me feedback i'll try to help you even more.

提交回复
热议问题