Caliburn.Micro
Caliburn.Micro copied to clipboard
Please use OnActiveAsync carefully
We need to implement the following functions:
- active a screen.
- open/switch a new view.
- reload some datas by active/init.
We can't use OnActiveAsync to load data. This will Put off the view display before async method finish. The solution is OnViewLoaded, BUT it can't await.
@a44281071 are you asking for OnViewLoaded to be an async event?
@vb2ae Maybe something like "Before init/active" and "After init/active" is comfortable. Any better ideas?
I always stayed away from de the activate stuff because it was not async in previous versions and created a StartAsync Method in my BaseViewModel. Only drawback is that i have to implicit call the StartAsync
Reagrds
John Kattestaart @.***
Op ma 27 dec. 2021 om 04:58 schreef SamTi(三台) @.***>:
@vb2ae https://github.com/vb2ae Maybe something like "Before init/activ" and "After init/active" is comfortable. Any better idea?
— Reply to this email directly, view it on GitHub https://github.com/Caliburn-Micro/Caliburn.Micro/issues/789#issuecomment-1001318415, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACULQHSWRDHHFBXZTCH3KQLUS7P6TANCNFSM5KV3ZUOQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
Perhaps we need a series of tutorials to demonstrate the best way to use the new asynchronous methods (active, deactive, handle event)
One problem I've found with OnActivateAsync is, it is called just before IsActive is set to true (see Screen.ActivateAsync()). This means if you have a main viewmodel that uses OnActivateAsync to initialize and activate some sub viewmodel like a login viewmodel then the OnActivateAsync in the sub viewmodel will be skipped ConductorBaseWithActiveItem.ChangeActiveItemAsync(). In this scenario it will never be called.
Edit: Replaced the second link with the actual method where it is skipped.
Please add some override methods for Active/Deactive. Like BeforActiveAsync/AfterActiveAsync..
Conductor method ActivateItemAsync()
ambiguity.
protected override async Task OnInitializeAsync(CancellationToken cancellationToken)
{
var box1 = new BoxViewModel(new MaterialViewModel { DisplayName = "child 111." });
await ActivateItemAsync(box1);
// box1 didn't active before this parent actived.
await base.OnInitializeAsync(cancellationToken);
}
public async Task ClickButtonAddChildAsync()
{
var box2 = new BoxViewModel(new MaterialViewModel { DisplayName = "child 222." });
await ActivateItemAsync(box2);
// box2 actived because this parent actived.
}
+1 to that.
How can I activate a sub item from within OnActivateAsync
of the parent?
I just upgraded from Caliburn 3.2 to 4 and this breaks.
I'm having a similar issue migrating from 3.x to 4.x and we used to use OnInitialize
to do lots of things that would be displayed, now nothing is displayed until initialize is returned, seems like a completely different way to do this. And OnActivateAsync
can't be used either since nothing is displayed either before it returns. Before 4.x in 3.x view was displayed before OnInitialize
called as far as I can tell and would update if VM/UI changes. Now I can't do this unless using OnViewLoaded
which then isn't async/Task so it will block...
What are you doing in the OnInitialize? trying to get an idea on what the use case is
What are you doing in the OnInitialize? trying to get an idea on what the use case is
For example, running various async tasks like loading things from file etc. Things we want to show progress for.
Or load data from webapi/db/remote-io.
with my PR #898 the second method for Initialize is added as well. Since we have now the OnActivated() is there still a need for a async OnViewLoaded()?
Like asp.net Blazor, It have InitAsync() and AfterAsync(bool firstRender). Used for 'Load remote data/webapi, init(bind) JS module'.