How set Eventcallback<> by Code RRS feed

  • Question

  • User62590854 posted


    I apologize for my ignorance but I need helt to some base of C#

    I made a blazor component:

            <FidaBlazorUI.FlexContainer FlexBehaviour="FlexBehaviour.d_flex" @attributes="@Attributes">
                <FlexContainer Style="margin-right:0.31em">
                <FlexContainer Style="margin-right:0.31em">
                    <span>@Start - @End</span>
                <FlexContainer Style="font-size:0.9em">
                    <Button Text="@ButtonText"
                            ButtonClick="@(() => { ButtonClick.InvokeAsync(WorkSheet); })" />
    @code {
        public CalendarTemplate TemplateType { get; set; }
        public object WorkSheet { get; set; }
        public CalendarTaskType CalendarTaskType { get; set; }
        public bool Confirmed { get; set; }
        public string Nome { get; set; }
        public string Start { get; set; }
        public string End { get; set; }
        public string Place { get; set; }
        public EventCallback<object> ButtonClick { get; set; }
        private string style;
        public string Style
            get => style;
                style = value;
        public string ButtonText { get; set; }
    public CalendarTask()
    public CalendarTask(object workSheet, string nome, string start, string end, string place, string buttonText, EventCallback<object> buttonClick)
            this.WorkSheet = workSheet;
            this.Nome = nome;
            this.Start = start;
            this.End = end;
            this.Place = place;
            this.ButtonText = buttonText;
            this.ButtonClick = buttonClick;
    private Dictionary<string, object> Attributes = new();

    Where there is a button that invoke an EventCallback that return an object (Worksheet in my case).

    With a normal implementation the use of new Component and related Eventcallback would be:

        <FidaBlazorUI.FastCalendar.CalendarTask ButtonClick="@(val => { OnButtonClick(val); })" />

    But I need to instantiate a new CalendarTask by code like it:

    row.Child = new FidaBlazorUI.FastCalendar.CalendarTask(ws,
                                GetName(ws, "myName"),
                                txt.Translate("Open Task"), ????);

    The problem is that I dont know how pass the EventCallBack parameter  "ButtonClick"

    the equivalent in code of this lambda expression: ButtonClick="@(val => { OnButtonClick(val); })"

    Thankyou for help

    Friday, January 29, 2021 11:49 AM

All replies