JeremyLikness / BlazorMVVM

Implementation of MVVM pattern in Blazor
MIT License
34 stars 11 forks source link

Databinding and Dependency Properties? #2

Open legistek opened 5 years ago

legistek commented 5 years ago

I found your article and am the one who started the issue (https://github.com/aspnet/Blazor/issues/374) where the Blazor team responded about MVVM support. This is near and dear to my heart and I was a little disappointed by that response.

After exploring this issue in more detail myself I've concluded that while using INotifyPropertyChanged gets you a good part of the way, true data binding (a la WPF / UWP / Xamarin Forms), and something equivalent to dependency properties (which can be assigned Binding instances as well as property values), are nonetheless the way to go. Without that we'll never have true separation of concerns between the UI markup and the viewmodel code.

I've been able to make a great deal of progress toward an internal, proprietary framework for doing this, but would be interested in working on an open source version if there's community interest.

mysteryx93 commented 3 years ago

I was very excited about how smooth things are in Blazor -- until I need to update a model field that is used by 2 components. Doing a bit of research and... there's just no clear supported solution. Just hacks here and there.

From what I'm seeing, MVVM just doesn't seem to be drawing a lot of interest. Is there an alternative solution that is being encouraged by Microsoft or by the community?

JeremyLikness commented 3 years ago

@mysteryx93 the thing is, Blazor doesn't require property change notification as it has other mechanisms, so I wouldn't recommend it for green field projects. However, there is a major opportunity to migrate WPF and other MVVM apps to Blazor. I'm working on a reference app to demonstrate what I think is a good practice for view models and commands in Blazor apps. You can see the work in progress here:

https://github.com/JeremyLikness/ExpressionPowerTools/tree/miscellaneous-nice-things/samples/Blazor/BlazorMvvmExample

The key to updating multiple components is here:

https://github.com/JeremyLikness/ExpressionPowerTools/tree/miscellaneous-nice-things/samples/Blazor/BlazorMvvmExample/BlazorMvvmExample/Client/Shared

(See the MVVMWrapper).

As for an alternate solution, defining a service class and using Cascading Values seems to be a common approach.