Saturday, February 24, 2024

Rounded entry field using handlers in .NET Maui

Customizing the UI elements is challenging in app development when we are using cross platform mobile app development. UIs will be different in both the platforms but as a cross platform app developer they have to write a custom code to match the UI elements in both the platforms.

This customization was implemented using Custom Renders in Xamarin.Forms framework. Now in .NET Maui they are called as handlers. There are many ways to write handlers in Maui, for implementing rounded entry we use a  customized control approach. Handlers are global, to customize a specific Entry control on a page that contains multiple Entry controls, you should first subclass the Entry control.

You can then customize the EntryHandler, via its property mapper, to perform the desired modification only to CustomEntry instances:

If the handler customization is performed in your App class, any CustomEntry instances in the app will be customized as per the handler modification.
Consuming custom controls in XAML file:

Final outcome of this implementation is here:

Complete project can be found here: https://github.com/GovardhanNag/EditorRenderer.git


Saturday, February 17, 2024

Device ID from iOS and Android platforms using .Net MAUI

In most of the scenarios app developers require unique device Ids to identify the duplicasy of their apps, or to encrypt their data with salt key as device Ids. So to get these device Id's we have to write a platform specific code in .NET Maui. In Xamarin.Forms we rely on Dependency Services to write the platform specific code, but in .NET Maui this can be achieved by creating partial classes. Here I'll explain step by step procedure for obtaining device Id's from partial class.

Cross platform partial class

Create a partial class and partial method, that will be implemented in platform specific partial classes.

 

GetDeviceInfo - Cross platform

With the GetDeviceID method we should obtain device Id's from each platform. 
Note: all the partial classes should have the same namespace, even though they are created in different folders, their namespace should match each other.

Android partial class 

Navigate to Platform\Android folder in the project solution and create another partial class.

iOS partial class 

Navigate to Platform\iOS folder in the project solution and create another partial class.

Here is how we call the platform specific partial method in our MainPage.xaml.cs file.

 
Finally the outcome of this implementation is here:
iOS Device id
Android Device Id




















SSO login using Launcher in .NET MAUI

  Some of the scenarios require to open the external/system browser to perform oAuth 2.0 login and then receive the auth code via redirect U...