C# Events and Delegates Made Simple | Mosh
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking about C# events and delegates, especially for passing data between pages or forms and wiring up callbacks in Xamarin, WPF, UWP and WinForms.
Recommended by 5 people across 5 different months, 2016 to 2023.
What it is
A 32-minute C# tutorial by Mosh Hamedani that explains delegates and events using a video-encoding example, covering how to define a delegate, declare an event based on it, and raise it. It is aimed at developers who find the publisher-subscriber pattern confusing.
What people said
Recommends sriman reddy · 2016-05 · Stack Overflow · on “Best place to load data from service in xamarin forms MVVM”
For your problem, you can use C# Events (Publisher-Subscriber) as the solution Write a event called InternetDisconnectedEvent in the View Model. Subscribe to that event in Code behind of the View (.xaml.cs) Make UI Changes in the View, when internet disconnected. For more about Event & Delegates, check this tutorial [this video]
Recommends KatiaChumakova · 2017-05 · Stack Overflow · on “How do you pass data from Navigation.PopAsync to previous page?”
I saw a video [this video] on Events and Delegates and got it running! Page1: public partial class Page1 : ContentPage, INotifyPropertyChanged { public static int _player; public static int Player { get{ return _player; } set{ _player = value; } } public NewGameH(string homeTeam, string opponentTeam) { InitializeComponent(); } public void OnPlayerSet(object source, EventArgs e) { System.Diagnostics.Debug.WriteLine("Begin Player {0} ", Player); } async void button1_Clicked(object sender, System.EventArgs e) { var page2 = new Page2(); page2.PlayerSet += this.OnPlayerSet; await Navigation.PushAsync(page2); } } Page2: public partial class Page2 : ContentPage{ public delegate void SetPlayerEventHandle
Recommends LempsPC · 2018-07 · Stack Overflow · on “UWP accessing parameter from another class”
Thank you for your answer. Followed documentation on MSDN and also this youtube video: [this video] and now it works like a charm.
Recommends mechbaral · 2018-11 · Stack Overflow · on “Basic of Event and Delegate. Event Subscribe line of PropertyChange Event from INotifyPropertyChanged in the class using it”
Hi I learned about event and delegate from [this video] . In this he says To make the event we need three step Define a Delegate Define an event based on that delegate Raise that event I followed him and made the app in Console but since i am working in WPF I will post the code that i used in WPF here and the code is as below: namespace WpfApp5 { public delegate void step1DelegateDefinition(); // Step-1: Define a delegate public interface INotifyOnVideoEncoded { event step1DelegateDefinition EventDefinedInInterface;// Step-2a: Define an event based on that delegate } public partial class MainWindow : Window, INotifyOnVideoEncoded { public event step1DelegateDefinition EventDefinedInInterface; //S
Recommends OldAndRetired · 2023-12 · Stack Overflow · on “create event in parent from from child from contained within a panel of parent form”
Thank you everyone for the help. I ended up using a custome event as sugested by jmcilhinney and GuidoG. jmcilhinney , I read through your execelent post about events but still had to search more to figure it out. Between your post and this video by Mosh, I got everything to work. [this video] Again, thank you everyone. What I like about this. There are going to be a number of more child forms that I want to do the same thing, and it will be easy to add them by doing things this way.
Cites Mike Ainsel · 2017-04 · Stack Overflow · on “Invoking class method from the Controller”
I am trying to add webapi (owin.selfhosting) support to existing C# console app and I have problem with callbacks from the controller. Essentially I need to call a function as a reaction to the http request. I think it's possible with delegates/events, but so far no success . Update: Using static event seems to work, I used a standard pattern as described in this video ( [this video] ) and adding a static keyword before event declaration. But mixing static delegate with non static subscriber probably is not the best practice. Code sample : //appcontroller.cs public class AppController : ApiController { public delegate void EventHandler(object source, EventArgs args); public static event EventHand