.NET MAUI is now a reality! After so many months of speculations, previews and rumors Microsoft officially launches the first Release Candidate of the cross-platform application development platform .NET MAUI!
As a spoiler, these new features are already available for the latest version of Microsoft’s IDE: Visual Studio 2022 (although for the moment for Mac you will have to follow, according to Microsoft, the command line instructions).
Cross-Platform SDKs
This first Release Candidate of .NET MAUI includes cross-platform SDKs (Windows, iOs, Android and macOS). One of the main advantages of .NET MAUI is that these SDKs can be easily used with C#. This allows you to “reuse” code from other platforms (cross-platform compatible code) allowing you to get the most out of .NET MAUI.
This is a big step forward because cross-platform application development will be much easier and more efficient (something I know many .NET developers were expecting from Microsoft).
Layouts and Controls
Another new feature of .NET MAUI Release Candidate 1 is that Microsoft adds new layouts and controls (more than 40). All these layouts and controls are prepared and optimized to be able to adapt to any type of user interface (both for mobile applications and desktop applications).
These more than 40 controls are mainly divided into 3 categories:
The great thing about this is that in .NET MAUI, we will also have all of the Xamarin.Forms UI controls.
Another great advantage is that there is the possibility of using blazor application components to make an equal experience in web applications, desktop applications and mobile applications.
New .NET MAUI Template
We are going to continue with new design features and this is a good one too.
Now Microsoft has decided to create a new .NET MAUI project template. The improvement here is that now we will be able to set the styles, colors and color palettes we want in the default stylesheet Resourcesstyles.xaml
. This way all the controls will load the styles that we are going to define in that style sheet.
Here is the Microsoft example:
<Style TargetType="Entry">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
<Setter Property="FontFamily" Value="OpenSansRegular"/>
<Setter Property="FontSize" Value="14" />
<Setter Property="PlaceholderColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource LightGray}, Dark={StaticResource DarkGray}}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
This is a very good possibility if we don’t have the need for different platforms (desktop or mobile) to load different types of styles, this way it will always load the same style for all platforms sharing the theme.
Customized controls
We continue with customization. Microsoft now adds the ability to modify controls explicitly on a particular platform. Using low-code hooks we can explicitly set different conditions or styles for a specific platform that are different from the rest.
The example shown by Microsoft is to remove the underline of an Entry
field only on the Android mobile platform:
#if ANDROID
Microsoft.Maui.Handlers.EntryHandler.Mapper.ModifyMapping("NoUnderline", (h, v) =>
{
h.PlatformView.BackgroundTintList = ColorStateList.ValueOf(Colors.Transparent.ToPlatform());
});
#endif
The advantage of this is that the amount of code needed to customize the style of the controls is very small and only has to be executed at application startup time.
Microsoft leaves us another more visual example:
<Border Stroke="{StaticResource Black}"
StrokeThickness="2"
StrokeShape="Rectangle">
<Entry
Margin="20,4"
Placeholder="Username" />
</Border>
The result:
This will allow a great customization whatever the scenario and the platforms for which the application is developed.
I remind you that this is Release candidate 1 and that you can now officially use .NET MAUI (with official Microsoft support) to develop your cross-platform applications!
Top comments (1)
I still wish they roll out proper Linux support