r/csharp • • 2d ago

Blog MVVM in C#: What Changes When You Switch UI Frameworks?

https://www.qt.io/blog/mvvm-csharp-when-you-switch-ui-frameworks

Hello, Miguel from Qt (qt.io) here. Following the release of the Qt Bridge for C#, I'd now like to share with you our latest blog post addressing some of the questions that we've since been asked.

"If I change UI frameworks, will the C# MVVM backend of my application still work?" This is the most frequent question that we've received from developers since releasing the Qt Bridge for C#. We wanted to provide some detailed information to back the answer to that question, which is: yes, when moving to a Qt Quick / QML UI, your C# MVVM backend will still work in the exact same way.

57 Upvotes

3 comments sorted by

7

u/Dunge 2d ago

I'm aware this post is a vendor specific advertisement for Qt. But let me answer the question in a more general way from personal experience. I had a MVVM WPF app using reactiveui for most of the viewmodel logic. Wanted to port it to Blazor and re-use the viewmodels. Will be easy right, just have to create a few .razor html pages and pass the proper variables?

Well no, it took a whole year. Blazor isn't built with the propertychanged/observablecollection concept in mind, and refreshing views with StateHasChanged() is very different. Problems like too many refresh that need batch updates. Then comes the fact that most components, might it be a treeview, a datagrid, or a map control all have their own nitpicks depending on UI library and can't just be re-used the same way. Event handlers routing not having the same parameters. And more issues.

3

u/mecfc 1d ago

One of the main goals of the C# Bridge is precisely to avoid this sort of situation where you spend most of the time trying to fit the pieces together instead of actually developing your app. Which is why support for the INotifyPropertyChanged and INotifyCollectionChanged protocols was part of the design from day-one. We're still working on a better support for ICommand. That one, though, is a bit trickier because the command logic is somewhat split between the ViewModel and View, which muddies a bit the separation of concerns. For now, calling the ICommand functions directly from QML is the way to go.

5

u/wubalubadubdub55 2d ago

This is great!