locked
How set Eventcallback<> by Code RRS feed

  • Question

  • User62590854 posted

    Hello,

    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">
                    <span>@Nome</span>
                </FlexContainer>
                <FlexContainer Style="margin-right:0.31em">
                    <span>@Start - @End</span>
                </FlexContainer>
                <FlexContainer>
                    <span>@Place</span>
                </FlexContainer>
                <FlexContainer Style="font-size:0.9em">
                    <Button Text="@ButtonText"
                            Type="BtnType.button"
                            ButtonStyle="BtnStyle.primary"
                            ButtonClick="@(() => { ButtonClick.InvokeAsync(WorkSheet); })" />
                </FlexContainer>
            </FidaBlazorUI.FlexContainer>
    @code {
    [CascadingParameter]
        public CalendarTemplate TemplateType { get; set; }
        [Parameter]
        public object WorkSheet { get; set; }
        [Parameter]
        public CalendarTaskType CalendarTaskType { get; set; }
        [Parameter]
        public bool Confirmed { get; set; }
        [Parameter]
        public string Nome { get; set; }
        [Parameter]
        public string Start { get; set; }
        [Parameter]
        public string End { get; set; }
        [Parameter]
        public string Place { get; set; }
        [Parameter]
        public EventCallback<object> ButtonClick { get; set; }
        private string style;
        [Parameter]
        public string Style
        {
            get => style;
            set
            {
                style = value;
                Attributes.SetStyleKey(value);
            }
        }
        [Parameter]
        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"),
                                row.Start.GetFormattedTime(TimeSpanFormat.HourMinutes),
                                row.End.GetFormattedTime(TimeSpanFormat.HourMinutes),
                                GetPlace(ws),
                                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