dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 168 forks source link

WFP blazor Support MVVM in future release? #465

Closed GreggAtCarfac closed 1 year ago

GreggAtCarfac commented 1 year ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

Hello

We find it very interesting to combine Blazor pages with wpf and are testing how far we can go with this. I have created a multi screen wpf application with Razor pages and ViewModels (MVVM) using Microsoft.Extensions.DependencyInjection. We notice if we change a property on 1 screen, it does not update on the other screen. Not even when we call the Onpropertychanged event.

is this support coming in a future release?

Describe the solution you'd like

the 2nd screen should update on the propertychange.

Additional context

No response

javiercn commented 1 year ago

@GreggAtCarfac thanks for contacting us.

You might be looking for MobileBlazorBindings. If you are looking for some way of using MVVM with Blazor components, I do not think there is anything that prevents you from doing so, but we do not have plans to more directly support the pattern in the framework.

Whether it is one or the other, none of the two pieces at this point are committed.

/cc: @Eilon

GreggAtCarfac commented 1 year ago

@javiercn Sorry is not resolved. yes the mobileblazorbindings is what i am doing. but it does not work multi screen. in a desktop wpf project i have 2 screens sharing the same viewmodel but if i click the counter button 3 times on screen 1 i see the counter increase from 0 to 1, then to 2 and finally 3 but on screen 2 it remains zero. if i then press the counter button on screen 2 once it jumps to 4. so i am sure they share the same viewmodel. and i do call the onproperychanged event so i would expect screen 2 to update if the counter on screen 1 button is pushed.

Eilon commented 1 year ago

I transfered this to the Mobile Blazor Bindings repo.

I'm not familiar with how multi-screen/window works, but in any case, to get each page to update you'll need the model type to have some sort of change notification that occurs any time the model (such as the counter value) changes. Then each page using that model can listen to that change notification and call StateHasChanged() to cause the UI to update.

To see an example, look at how and where this event is used in a ToDo sample app: https://github.com/dotnet/MobileBlazorBindings/blob/main/samples/MobileBlazorBindingsToDo/AppState.cs#L31

GreggAtCarfac commented 1 year ago

@Eilon Thanks for the help. Your solution worked. Its a but sad that you have to force the screens to update through the StateHasChanged() event on the blazor pages themselves. You would think as the view is bound through dependency injection with its viewmodel a simple onpropertychanged event on the viewmodel would be enough and no code is needed on the view. I hope the developers will add this in a future release.