What better way to catch up from my vacation than to check out the latest updates to .NET MAUI content via NuGets and YouTube videos? Ya'll been busy! Here we go:
NuGets
Source Generators
Are you looking for source generators to reduce the boilerplate code you need to write when creating bindable properties for custom components? Here are a few options:
MauiReactor is an MVU "Component based UI library inspired by ReactJS and Flutter", and the successor to ReactorUI which was based on Xamarin.Forms. Coupled with it's own Hot Reload component, and you have a nice, productive C# first development experience.
using MauiReactor.WeatherTwentyOne.Pages.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MauiReactor.WeatherTwentyOne.Pages
{
internal class HomePage : Component
{
public override VisualNode Render()
{
return new ContentPage(title: "Redmond, WA")
{
Device.Idiom == TargetIdiom.Desktop ?
RenderDesktopLayout()
:
RenderPhoneLayout()
};
}
private VisualNode RenderPhoneLayout()
{
return new ScrollView
{
new VerticalStackLayout
{
new CurrentWidget(),
new BoxView()
.HeightRequest(1),
new Next24HrWidget(),
new Next7DWidget()
}
.Padding(0,50)
.Spacing(25)
};
}
private VisualNode RenderDesktopLayout()
=> new Grid(
rows: "*",
columns: "*,500")
{
new ScrollView
{
new VerticalStackLayout
{
new FlexLayout
{
new CurrentWidget()
.Width(200),
new WindLiveWidget(),
}
.MinimumHeightRequest(360)
.AlignItems(Microsoft.Maui.Layouts.FlexAlignItems.Center)
.AlignContent(Microsoft.Maui.Layouts.FlexAlignContent.Center)
.JustifyContent(Microsoft.Maui.Layouts.FlexJustify.SpaceEvenly),
new BoxView()
.HeightRequest(1),
new Next24HrWidget(),
new Next7DWidget()
}
.Padding(0,50)
.Spacing(50)
},
new WidgetsPanel()
.GridColumn(1)
};
}
}
SkiaSharp.Views.Maui.Controls
This set of SkiaSharp views can be added to any .NET MAUI application for drawing. This is similar to what you can do with the built-in GraphicsView and Microsoft.Maui.Graphics, but directly to SkiaSharp.
private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
// the the canvas and properties
var canvas = e.Surface.Canvas;
// make sure the canvas is blank
canvas.Clear(SKColors.White);
// decide what the text looks like
using var paint = new SKPaint
{
Color = SKColors.Black,
IsAntialias = true,
Style = SKPaintStyle.Fill,
TextAlign = SKTextAlign.Center,
TextSize = 24
};
// adjust the location based on the pointer
var coord = (touchLocation is SKPoint loc)
? new SKPoint(loc.X, loc.Y)
: new SKPoint(e.Info.Width / 2, (e.Info.Height + paint.TextSize) / 2);
// draw some text
canvas.DrawText("SkiaSharp", coord, paint);
}
OnScreenSize XAML Markup Extension
Just like with OnPlatform and OnIdiom, you can specify different values to control properties based on screen dimensions with this library. This looks useful, so long as you agree on the predefined sizes I suppose. This doesn't look like it would be adaptive at runtime. For this I recommend using adaptive triggers and providing your own size requirements.
OnScreenSizeMarkup is a XAML markup extension for controlling UI elements (Views) based on the category a device's screen sizes fits in (Medium-sized devices, Large-sized devices, and etc).
This project is based on a post I wrote a long time ago for my blog.
Maui Community Toolkit announcement
I'm pround to anounce that this project will be soon moved to Maui Community Toolkit as per these conversation.
As it is now ready for MAUI, it just a matter of days to be ported to the MCT and wait to the next release ef the Toolkit to be published.
OnScreenSizeMarkup: A XAML markup extension
OnScreenSizeMarkup is XAML markup extension for controlliing UI elements depending on the device screen size category.
Where can I use it?
OnScreenSizeMarkup is currently compatible with:
Xamarin.Forms
MAUI
What does that mean?
It works exactly as other markup extensions such as OnPlatform or OnIdiom, allowing you to control UI views accordding to the screen sizes category a device fits in.