[SOLVED] Adding a custom event

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
MichaelHughes
Posts: 41
Joined: Thu Oct 08, 2015 5:33 am

[SOLVED] Adding a custom event

Postby MichaelHughes » Thu Jul 04, 2019 11:41 pm

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

TaterJuice
Posts: 147
Joined: Thu Mar 16, 2017 5:40 am
Contact:

Re: Adding a custom event

Postby TaterJuice » Fri Jul 05, 2019 7:42 am

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 });
    }
}

MichaelHughes
Posts: 41
Joined: Thu Oct 08, 2015 5:33 am

Re: Adding a custom event

Postby MichaelHughes » Sun Jul 07, 2019 11:15 pm

Many thanks

Mike


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 36 guests

 

 

cron