Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] LazyView always loads the BindingContext #1408

Answered by auriou
auriou asked this question in Q&A
Discussion options

You must be logged in to vote

I solved my problem by implementing a class that inherits from LazyView

public class CustomLazyView<TView> : LazyView<TView> where TView : View, new()
{
    public static readonly BindableProperty ViewModelProperty =
        BindableProperty.Create(nameof(ViewModel), typeof(Type),
            typeof(CustomLazyView<TView>), default);

    public Type ViewModel
    {
        get => (Type)GetValue(ViewModelProperty);
        set => SetValue(ViewModelProperty, value);
    }

    public override ValueTask LoadViewAsync()
    {
        if (ViewModel != null)
            BindingContext = Resolver.Resolve(ViewModel);

        return base.LoadViewAsync();
    }
}
<xct:TabViewItem Style="{StaticRes…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@pictos
Comment options

@auriou
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by auriou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn't working. Breaky break. s/unverified This issue needs verification/reproduction by a team member. PRs cannot be accepted/merged.
2 participants
Converted from issue

This discussion was converted from issue #1407 on June 16, 2021 23:41.