Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsInitialized and IsActive are set too early #593

Closed
mgnsm opened this issue Mar 25, 2019 · 1 comment
Closed

IsInitialized and IsActive are set too early #593

mgnsm opened this issue Mar 25, 2019 · 1 comment

Comments

@mgnsm
Copy link
Contributor

mgnsm commented Mar 25, 2019

IsInitialized shouldn't be set to true before the OnInitializeAsync method has returned and the view model has actually been initialized.

Consider a view model that performs some asynchronous initialization:

public class SampleViewModel : Screen
{
    protected override async Task OnInitializeAsync(CancellationToken cancellationToken)
    {
        await Task.Delay(5000); //simulate doing something...
    }
}

And a view that displays a spinner or message to indicate that the view model is being initialized:

<TextBlock>
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Setter Property="Text" Value="Ready!" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsInitialized}" Value="False">
                    <Setter Property="Text" Value="Initializing..." />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

In version 4.0.52-alpha, the "Initializing..." message will never displayed because the IsInitialized property is set to true before the OnInitializeAsync method is awaited in the Screen class.

The same thing applies to IsActive and OnActivateAsync/OnDeactivateAsync.

These properties should be set once the tasks have completed. I'll submit another pull request.

nigel-sampson added a commit that referenced this issue Mar 25, 2019
#593 Set the IsInitialized and IsActive properties to true only after…
erik-hooper added a commit to erik-hooper/Caliburn.Micro that referenced this issue May 25, 2023
This is in relation to
Caliburn-Micro#593.
I agree with the issue but is a pretty big breaking change. This should allow the correct sequence of activation, activated callbacks.
@a44281071
Copy link

a44281071 commented Jun 7, 2023

Shall we change it to Activating/Activated?Or before/after?
We can test this sample code SampleViewModel => SampleView : Window. Will the window immediately display?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants