Page 1 of 1

[SOLVED] Adding a custom event

Posted: Thu Jul 04, 2019 11:41 pm
by MichaelHughes
Adding a custom event to a class.

I am trying to use a custom event with a class. I'd usually be in WPF and use EventManager to create a RoutedEvent.

Can you give an example of creating a RoutedEvent say CustomEvent with CustomRoytedEventArgs cusing cshtml5. Most of the bits I would expect to use are missing from the documentation.

Or I could be wrong of course :-D but a simple example so I can use

CustomEvent=handler in Xaml

and obj.CustomEvent+=handler in c#

with CSHTML5


Many thanks

Re: Adding a custom event

Posted: Fri Jul 05, 2019 7:42 am
by TaterJuice
How about this

Code: Select all

public class ClickableCollection
{
    public delegate void ItemClickEventHandler(object sender, ItemClickEventArgs e);
    public event ItemClickEventHandler ItemClick;
    public class ItemClickEventArgs : EventArgs
    {
        public object ClickedItem { get; internal set; }
    }
    private void OnClicked(object clickedItem)
    {
        ItemClick?.Invoke(this, new ItemClickEventArgs() { ClickedItem = clickedItem });
    }
}

Re: Adding a custom event

Posted: Sun Jul 07, 2019 11:15 pm
by MichaelHughes
Many thanks

Mike