Blazor Component Events using EventCallback

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ย. 2024

ความคิดเห็น • 8

  • @ximonx
    @ximonx 5 ปีที่แล้ว

    Nice example! Was a huge help!

  • @Sammy0021
    @Sammy0021 5 ปีที่แล้ว +1

    Nice tutorial...
    by the way which fonts are u using for the visual studio code editor...its very nice

  • @yuriygo
    @yuriygo ปีที่แล้ว

    Demo projects are not compiled due to multiple errors...There is no method such as OnInit(). It should be OnInitializedAsync()

  • @enetstudio4176
    @enetstudio4176 5 ปีที่แล้ว +4

    You should ensure that the EventCallback object has a delegate before you invoke the delegate, like this:
    if (OnSelected.HasDelegate)
    {
    OnSelected.InvokeAsync(this.DayOfWeek);
    }

    • @gogoku7
      @gogoku7 5 ปีที่แล้ว

      I have never really worked with Event and Delegate, what's the purpose of if(OnSelected.HasDelegate) ?

    • @AngusMcIntyre
      @AngusMcIntyre 5 ปีที่แล้ว

      The modern pattern can perform all this in one line: OnSelected?.Invoke(sender, args);

  • @svyatoslavstrygin5653
    @svyatoslavstrygin5653 4 ปีที่แล้ว

    worx, thank you!

  • @TonyHenrique
    @TonyHenrique 4 ปีที่แล้ว +1

    Very nice! Just tried it here with a custom class for my event, and it only worked if it inherit from EventArgs
    Like:
    public class MyCustomEventData : EventArgs
    ...then using it like:
    [Parameter]
    public EventCallback OnArquivoEnviado { get; set; }
    ///////
    var mce = new MyCustomEventData() { ... }
    await OnArquivoEnviado.InvokeAsync(mce);
    ////////
    To Bind it:
    public void Enviado(MyCustomEventData d)
    {
    }
    // Hope this helps somebody.