adospace / reactorui-maui

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

Create a custom component #93

Closed MattePozzy closed 1 year ago

MattePozzy commented 1 year ago

Hi, I need to create a custom component made with a label and an entry both wrapped in a Grid container.

I have created this class:

 public partial class VolosEntry : Grid
    {
        public VolosEntry LabelText(string valore)
        {
            this.label.Text(valore);
            return this;
        }

        public Label label;
        public Entry campo;

        public VolosEntry()
        {
            this.Columns("1");
            this.Rows("2");

            label = new();
            label.GridRow(0).GridColumn(0);
            campo = new();
            campo.GridRow(1).GridColumn(0);

            Add(label);
            Add(campo);
        }
    }

and used like this: image

but nothing is rendered.

How can I solve this?

Thank you.

MattePozzy commented 1 year ago

I did it!

For reference this is my components:

public class VolosEntry : VStack
    {
        public Label label;
        public Entry campo;

        public VolosEntry()
        {
            label = new();
            campo = new();

            Add(label);
            Add(campo);
        }
    }

    public static class VolosEntryExtensions
    {
        public static T LabelText<T>(this T label, string text) where T : VolosEntry
        {
            ref T val = ref label;
            T val2 = default(T);
            if (val2 == null)
            {
                val2 = val;
                val = ref val2;
            }

            val.label.Text(text);
            return label;
        }

        public static T LabelText<T>(this T label, Func<string> textFunc) where T : VolosEntry
        {
            ref T val = ref label;
            T val2 = default(T);
            if (val2 == null)
            {
                val2 = val;
                val = ref val2;
            }

            val.label.Text(textFunc);
            return label;
        }
    }