This post about developing ASP.NET Core apps with Xamarin Forms and Ooui. Xamarin.Forms exposes a complete cross-platform UI toolkit for .NET developers. Build fully native Android, iOS, and Universal Windows Platform apps using C# in Visual Studio. And Ooui is a small cross-platform UI library that brings the simplicity of native UI development to the web. In the background, it is also using WebAssembly, like Blazor. Here is a simple console app, which is running a Xamarin Forms code in self hosted mode.
First I created a console application using
dotnet new console command and then added reference of
Ooui library. This app is creating a button in the UI and publishing the page to
http://localhost:8080. You may need to run the app as administrator, either ways you may get an access denied message. You can run the application using
dotnet run, once you run, open browser and try to access localhost:8080, you will be able to see a bootstrap primary button and text will be updated when you click on it.
In this example, you’re running Xamarin Forms but only using code. You can design Xamarin forms with Visual Studio and use it in the application. And you need to add reference of
Xamarin.Forms. Next you can add a new file, and modify the code like this.
Run the application and browse it, you will be able to see the Page running in Browser.
So far we used the Xamarin Forms in Console app. Ooui provides a middleware and Action Result implementation to use it in ASP.NET Core. So to use it with ASP.NET Core, first you need to add the reference of
Ooui.AspNetCore package. Then in the startup code add following code.
Once it is done, you write code to return Page as View like this.
This will return the HelloWorld Page as View, when opening the Index action. Here is the app running on my system.
Which is better - Blazor or Ooui?
Both of the frameworks is using Web Assembly. Since Blazor is in very early preview stages, it is difficult to compare, but here is some pros and cons I found while exploring Ooui and Blazor.
- Built on top of Razor - Easy for MVC developers to build apps on top.
- Can choose any UI framework, lot of customization options, full control on the generated HTML.
- From ASP.NET Team.
- No debug support so far.
- Experimental (Not ready to use in production apps)
- Using Xamarin Forms for developing UI - Existing mobile app UIs can be reused.
- Design support with Visual Studio.
- Debugging Supported with Visual Studio.
- Support for UX design patterns like Command pattern, Two way binding, MVVM etc.
- No control on the HTML rendering.
- Tightly coupled with Bootstrap.
Here is few pros and cons about the two frameworks, let me know if you find this post useful.
Happy Programming :)