DEV Community

Cover image for Cross-Platform app with C# and Uno Platform - Part 2
Amit
Amit

Posted on

Cross-Platform app with C# and Uno Platform - Part 2

In part 1, I covered a bit of intro to Uno Platform and the app built on it. I'll close with some thoughts on cross platform development, challenges and alternatives for Uno Platform here and wrap up.

Let's talk Cross Platform

Single codebase means simpler maintenance - a feature upgrade is a single change for all platforms. This also means simpler testing and build pipeline too, as you don't need one for every platform or the associated language used for that platform. It does make a good case for itself and seems pretty logical when you think about it, right? If your team is proficient in C# then you're good. If not, how long are you willing to wait, if you are willing to?

You can visit the technology showcase section of Uno Platform, React Native, Flutter and Xamarin and it looks like there are quite a few of them.
On the flip side, there's this article from Airbnb and one from Dropbox as well, where they went back to native.

So, does a single, shared codebase work for everyone or not? Only way to find out is probably by trying out a sample (and slightly complicated app) and see how it goes, or an internal non-customer facing app to get a feel of how it would work.

Third-Party UI Controls for Uno Platform

In the previous post, I mentioned Windows Community Toolkit for UI controls, but in .NET apps on Windows (WPF, UWP, ASP.NET Core etc.) you have a lot of options for third party controls. With Uno, the documentation lists Syncfusion and Infragistics. Now this app that I have created, is a cut-down version of the Web Assembly version that I created with Blazor. The main reason for this is I don't have those chart controls here for me.

With Syncfusion, it required adding their entire project locally to the solution to integrate it and there was no license specified at that time, so I skipped it. It seems to be resolved now though. Infragistics looks good too but they have a trial license which I didn't go for at that time.

I cannot comment on these as I haven't used them but they are available for Uno.

What about Mac?

I started out with the target to have the app run on Windows, Mac, Linux and Android. It worked fine on all except for the Mac. This is due to the way I have created the sample and let's see what that is. UWP allows us to set visual breakpoints and set visual state for each of those. As seen in this example -

<x:Double x:Key="MinWindowBreakpoint">0</x:Double>
<x:Double x:Key="MediumWindowBreakpoint">641</x:Double>
<x:Double x:Key="LargeWindowBreakpoint">1008</x:Double>

Enter fullscreen mode Exit fullscreen mode

We can then specify the Data Template, to optimize the view for that size, and this gets triggered depending on the dimensions specified in the breakpoint. Think of this as a CSS media query, to make it easier to relate to.
In our case, I also have the command in the viewmodel that fetches data on startup, asynchronously. This data is being bound to the DataGrid which is present in the above Data Template. This somehow doesn't work on Mac, while it works fine on other platforms.
I have opened a GitHub issue for this and until then, I have the app in Mac without any data, to show that it does launch and also is responsive (visual adaptive breakpoints).

App with default width on Mac


With Default Width

if I minimize the app horizontally, it gets to the small breakpoint and readjusts accordingly/

Responsive small width


Reduced width to see the responsive UI

The Players

There are quite a few alternatives and I'll just list them here as I haven't tried all of them.

  • Flutter - Google's UI toolkit offering, using Dart.
  • React Native - Apps for Android and iOS, using React.
  • React Native for Windows and Mac - An interesting option to bring React Native apps to Windows and Mac!
  • Xamarin - Extending .NET to multiple platforms including watchOS and tvOS.
  • .NET MAUI - Evolution of Xamarin.Forms, currently in preview.
  • Electron - Cross platform desktop apps for Windows\Mac\Linux. VS Code is built with Electron.

What Next?

Probably one last port of this app to .NET MAUI, Microsoft's upcoming offering, for comparison. React Native for Windows and Mac looks good for experimenting too.

Choice is good.

Cover image credit

Top comments (0)