Quantcast
Channel: User Liyun Zhang - MSFT - Stack Overflow
Viewing all articles
Browse latest Browse all 445

Answer by Liyun Zhang - MSFT for Why is two way bind value not working? Maui Blazor Hybrid app

$
0
0

First of all, I reproduced you problem with the await Task.Delay(1000);:

private async Task PushToDatabaseFunction() {     await Task.Delay(1000);   statusLabelBindString = $" {inputFieldString} was added to db";}

The code above can reproduce your problem. And I can fix it in two ways:

  1. Call the StateHasChanged() manually, so you can also try it:
if(db.status=="ok"){   statusLabelBindString = $" {inputFieldString} was added to db";   StateHasChanged();} else{   statusLabelBindString = "Error - Duplicate value";   StateHasChanged();}
  1. Delete the await in await Task.Delay(1000);:
private async Task PushToDatabaseFunction() {     Task.Delay(1000);   statusLabelBindString = $" {inputFieldString} was added to db";}

The two ways can bot update the label when you press the Enter first time.

So the problem is asynchronous method. UI is never refreshed (re-rendered) because the StateHasChanged() is never being called by the runtime because the runtime didn't know when the async methods called return.


Viewing all articles
Browse latest Browse all 445

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>