adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
568 stars 47 forks source link

Scaffold a third part component issue #111

Closed MattePozzy closed 1 year ago

MattePozzy commented 1 year ago

Hi, I have create this scaffolded component

[Scaffold(typeof(Syncfusion.Maui.ListView.SfListView))]
 public partial class VolosListView{}

but it hasn't created the method ItemsSource, so I have creted it


        public VolosListView ItemsSource(object lista)
        {
            this.Set(Syncfusion.Maui.ListView.SfListView.ItemsSourceProperty, lista);
            return this;
        }

the original components has the ItemTemplate method that has as parameters a datatemplate.

I need to have a method like the ItemTemplate that accepts a VisualNode but also that receive the current item of the listView, in such a way that I can assign the property of the current item to label, button and so on.

I have tried to do this, but doesn't work

 public VolosListView ItemTemplate(Func<object, VisualNode> template)
        {
            this.Set(Syncfusion.Maui.ListView.SfListView.ItemTemplateProperty,
                new MauiControls.DataTemplate(() => TemplateHost.Create(template(/*here i need to pass che current item*/)).NativeElement));
            return this;
        }

The original method use the Binding to set the value of labels ecc..

How can I do this?

Thank you.

adospace commented 1 year ago

Using the latest version you can scaffold SfListView and use it with a code like this:

[Scaffold(typeof(Syncfusion.Maui.Core.SfView))]
public abstract class SfView { }

[Scaffold(typeof(Syncfusion.Maui.ListView.SfListView), implementItemTemplate: true)]
public partial class SfListView 
{

}

class MainPageState
{
    public List<string> Items { get; set; } = new List<string>(new[] { "Item1", "Item2" });
}

new SfListView()
      .ItemsSource(State.Items, item => new Label(item))