Replies: 9 comments 39 replies
-
That's a very neat idea. Have you tried talking to @davidortinau or @PureWeen? |
Beta Was this translation helpful? Give feedback.
-
@idexus I would also prefer to construct the UI in a declarative way and your suggestion is very good. The problem is that now, for any change in the UI code we will have to rebuild the project to see the changes. Currently XAML hot reload is broken in MAUI. Sometimes it works, sometimes not. And there is no support for code hot reload. |
Beta Was this translation helpful? Give feedback.
-
@YiannisBourkelis I know there is no support for code hot reload, but personally for me, creating a UI in code only, using a declarative way, gives more value than the XAML approach. e.g. creating custom content views where all bindable properties are generated automatically form the interface declaration, and grid definitions and data bindings are created inline is far more readable in code then in XAML. example from my lib: [BindableProperties]
public interface ICardViewProperties
{
string CardTitle { get; set; }
string CardDescription { get; set; }
Color CardColor { get; set; }
Color BorderColor { get; set; }
Style DescriptionStyle { get; set; }
View ContentView { get; set; }
string ButtonTitle { get; set; }
}
[SharpObject]
public partial class CardView : ContentView, ICardViewProperties
{
public event EventHandler Clicked;
public CardView()
{
this.BindingContext = this;
Content = new Border
{
new Grid
{
new VStack
{
new Label()
.Text(e => e.Path(nameof(CardTitle)))
.FontSize(25)
.TextColor(Colors.White),
new Label()
.Text(e => e.Path(nameof(CardDescription)))
.Style(e => e.Path(nameof(DescriptionStyle))),
},
new ContentView()
.Row(1)
.Content(e => e.Path(nameof(ContentView)))
.HorizontalOptions(LayoutOptions.Center)
.VerticalOptions(LayoutOptions.Center)
.SizeRequest(120,120),
new Button()
.Row(2)
.Text(e => e.Path(nameof(ButtonTitle)))
.BackgroundColor(AppColors.Gray600)
.TextColor(AppColors.Gray100)
.OnClicked((sender, e) => Clicked(sender,e))
}
.RowDefinitions(e => e.Star(1).Star(2).Star(0.7))
.RowSpacing(10)
}
.StrokeShape(new RoundRectangle().CornerRadius(10))
.Stroke(e => e.Path(nameof(BorderColor)))
.BackgroundColor(e => e.Path(nameof(CardColor)))
.SizeRequest(200, 300)
.Margin(50)
.Padding(20);
}
} than you can use this in that way: new VStack
{
new Slider(1, 100, out var slider),
new CardView(out cardView)
.CardTitle(e => e.Path("Value").Source(slider).StringFormat("Value {0:F1}"))
.ButtonTitle("Play")
.CardDescription("Do you like it")
.CardColor(Colors.Blue)
.BorderColor(Colors.Red)
.ContentView(new Image("dotnet_bot.png").Aspect(Aspect.AspectFit))
.OnClicked(e =>
{
e.CardDescription = "Let's play :)";
})
} |
Beta Was this translation helpful? Give feedback.
-
You can use CommunityToolkit Maui Markup library: https://github.com/CommunityToolkit/Maui.Markup |
Beta Was this translation helpful? Give feedback.
-
Have you tried Comet? or AlohaKit? |
Beta Was this translation helpful? Give feedback.
-
Code over XAML is also my preferred approach, so I wrote a code generator that creates almost all of what I need automatically.
Ive also implemented multi binding with converter support:
This approach does not require any subclassing though. |
Beta Was this translation helpful? Give feedback.
-
I created a fork to build a fluent API support directly in the MAUI project (without wrapping and without subclassing) |
Beta Was this translation helpful? Give feedback.
-
Hi Everyone! There seems to be 2 main topics here:
First, thank you so much for this Discussion! I'm very excited to see this added to For more information, here's a blog post I wrote when we released the .NET MAUI Community Toolkits: https://devblogs.microsoft.com/dotnet/introducing-the-net-maui-community-toolkit-preview/ Let's pave a path forward here for anyone from the community who would help with this effort!
Edit: This is not possible until partial classes support external assemblies Most .NET MAUI Controls are already using a This means that we can create a second
Edit: This is not possible until partial classes support external assemblies
Edit: This is not possible until partial classes support external assemblies namespace Microsoft.Maui.Controls;
public partial class Button
{
public Button(Thickness padding = default,
LineBreakMode lineBreakMode = default,
Thickness margin = default
// continue adding a parameter for every Property of `Button`, including the properties inherited by `View`
)
{
this.Padding = padding;
this.LineBreakMode = lineBreakMode;
this.Margin = margin;
// continuing assigning every parameter to its Property
}
}
In the After each Proposal has been created, the Community Toolkit core maintainer team will review the Proposal and help refine the details. The team will then vote to Approve the implementation of each Proposal at our monthly standup. After each Proposal has been approved, any community member is welcome to submit a PR implementing it. Extension Methods for .NET MAUI PropertiesBelieve it or not, this is already an existing goal of Implementation
ExampleHere's an existing example from public static TView CenterHorizontal<TView>(this TView view) where TView : View
{
view.HorizontalOptions = LayoutOptions.Center;
return view;
} Next StepsIn the After each Proposal has been created, the Community Toolkit core maintainer team will review the Proposal and help refine the details. The team will then vote to Approve the implementation of each Proposal at our monthly standup. After each Proposal has been approved, any community member is welcome to submit a PR implementing it. |
Beta Was this translation helpful? Give feedback.
-
@idexus Love your work! Regarding hot reload, I've been able to get it working using C#-only UIs by using the approach outlined here: |
Beta Was this translation helpful? Give feedback.
-
--- new edit
I understand the reasons for the rejection of the PR. I also understand that more convincing reasons are needed. So earlier, I started an issue about adding a few things to the maui library to simplify non-XAML development (I don't understand why it was moved to the Community Toolkit). I don't mean methods exactly, because that can be handled with extension methods. However, there are things you can't do and be 100% compatible with maui classes like:
Interestingly, it doesn't build maui project inconsistency and if implemented inside maui project you wouldn't need to unseal the classes. The design will improve in my opinion, and the performance will not spoil. @hartez @PureWeen @davidortinau @mattleibow
Hot Reload example
--- old
I have created a fork to build a fluent API support directly in the MAUI project (without wrapping and without subclassing). I ported my lib with some minor changes to the MAUI and it works.
https://github.com/idexus/maui/.../info.md
I need your feedback!
--- old
I have created a small wrapper library to use .NET MAUI in a declarative way, without the need for XAML. It is mostly auto-generated.
https://github.com/idexus/Sharp.UI
Usage example
but unfortunately some classes are
sealed
so I have to make a wrapper for them.e.g.:
PathGeometry
,PathFigure
,TapGestureRecognizer
,PinchGestureRecognizer
,PointerGestureRecognizer
,SwipeGestureRecognizer
,Ellipse
,Polyline
,Line
,Path
,Polygon
,Rectangle
,RoundRectangle
,TableSection
,ColumnDefinition
,RowDefinition
Style
,Trigger
,... etc.If I want to create interface with these classes in a declarative way, I cannot do it without wrapping them.
My goal was:
Is there an option to unseal maui classes? It will make easier to create truly declarative way of creating interface, only in code.
Or my second question, can the Fluent API be implemented directly in the MAUI project?
Beta Was this translation helpful? Give feedback.
All reactions