If you can do it in XAML, you can do it in C#
Anything that can be declared in XAML can be declared in C#. Containment is managed by using the children
property of an object. Event handlers must be registered on an instance of the control. That is, an event handler would be registered for a particular button, as you’ll see in this example.
Here is the code we wrote in XAML converted to C#:
using CommunityToolkit.Maui.Markup; [1] namespace ForgetMeNotDemo; class MainPageCS : ContentPage { private readonly Button counterBtn = new Button [2] { Text = "Click Me", HorizontalOptions = LayoutOptions.Center, }.SemanticHint("Counts the number of times you click"); public MainPageCS() { counterBtn.Clicked += OnCounterClicked; [3] Content = new VerticalStackLayout...