Closed HubertBieder closed 9 months ago
MainLayout.Razor Can I get a MVVM Support for this Razor File also?
If not I have here a break in the MVVM Logic
@HubertBieder Not sure what you are asking. Please supply more information.
I Rebuild my Blazor App and want to use your concept of MVVM with the community Toolkit. Because I like your concept.
For Normal pages all worked well.
@page "/fetchdata"
@inherits MvvmComponentBase
public partial class FetchDataViewModel : ViewModelBase
But the MainLayout.razer is derived from
@inherits LayoutComponentBase
How can I use the MVVM Concept for this MainPage?
How doés the ModelView Class is derived ? And who it ist he notation in the razor file?
Von: Graeme @.> Gesendet: Sonntag, 8. Oktober 2023 23:27 An: gragra33/Blazing.Mvvm @.> Cc: Hubert Bieder @.>; Mention @.> Betreff: Re: [gragra33/Blazing.Mvvm] MVVM Support for MainLayout.razer (Issue #2)
@HubertBiederhttps://github.com/HubertBieder Not sure what you are asking. Please supply more information.
— Reply to this email directly, view it on GitHubhttps://github.com/gragra33/Blazing.Mvvm/issues/2#issuecomment-1752166164, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH2QDKP6EI2HXPBLSAYM5V3X6MLARAVCNFSM6AAAAAA5X4UGO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJSGE3DMMJWGQ. You are receiving this because you were mentioned.Message ID: @.**@.>>
@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.
Great! I will use it i if it is released.
Von: Graeme @.> Gesendet: Sonntag, 8. Oktober 2023 23:44 An: gragra33/Blazing.Mvvm @.> Cc: Hubert Bieder @.>; Mention @.> Betreff: Re: [gragra33/Blazing.Mvvm] MVVM Support for MainLayout.razer (Issue #2)
@HubertBiederhttps://github.com/HubertBieder For that, I will need to add a new LayoutComponentBase class. Something like:
public abstract class MvvmLayoutComponentBase
: 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.
— Reply to this email directly, view it on GitHubhttps://github.com/gragra33/Blazing.Mvvm/issues/2#issuecomment-1752169544, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH2QDKICRPTSR6QRMVER6D3X6MNBNAVCNFSM6AAAAAA5X4UGO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJSGE3DSNJUGQ. You are receiving this because you were mentioned.Message ID: @.**@.>>
@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.
Can I get a MVVM Support for this Razor File ?
If not I have here a break ikn dthe MVVM Logic