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

MVVM Support for MainLayout.razer #2

Closed
HubertBieder opened this issue Oct 8, 2023 · 6 comments
Closed

MVVM Support for MainLayout.razer #2

HubertBieder opened this issue Oct 8, 2023 · 6 comments

Comments

@HubertBieder
Copy link

Can I get a MVVM Support for this Razor File ?

If not I have here a break ikn dthe MVVM Logic

@HubertBieder
Copy link
Author

MainLayout.Razor
Can I get a MVVM Support for this Razor File also?

If not I have here a break in the MVVM Logic

@gragra33
Copy link
Owner

gragra33 commented Oct 8, 2023

@HubertBieder Not sure what you are asking. Please supply more information.

@HubertBieder
Copy link
Author

HubertBieder commented Oct 8, 2023 via email

@gragra33
Copy link
Owner

gragra33 commented Oct 8, 2023

@HubertBieder For that, I will need to add a new LayoutComponentBase class. Something like:

public abstract class MvvmLayoutComponentBase<TViewModel>
    : LayoutComponentBase, IView<TViewModel> where TViewModel : IViewModelBase
{
    [Inject]
    protected TViewModel? ViewModel { get; set; }

    protected override void OnInitialized()
    {
        // Cause changes to the ViewModel to make Blazor re-render
        ViewModel!.PropertyChanged += (_, _) => InvokeAsync(StateHasChanged);
        base.OnInitialized();
    }

    protected override Task OnInitializedAsync()
        => ViewModel!.OnInitializedAsync();
}

I need to run some tests, then I'll push an update.

@HubertBieder
Copy link
Author

HubertBieder commented Oct 8, 2023 via email

@gragra33
Copy link
Owner

gragra33 commented Oct 8, 2023

@HubertBieder v1.1.0 was just pushed to Nuget. Give it a few minutes to be processed.

I've also added a demo to the sample project. It's a simple Navigation count. Click on the page links on the left and the count will increment.

@gragra33 gragra33 closed this as completed Oct 8, 2023
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

2 participants