i\'ve created an UserControl for Database connection where user input Username and Password for a connection. This UserControl is in a MainWindow.xaml
Now, in code behin
First create a public event in your class :
public event EventHandler SomethingChanged;
NB MyEventArgs
is the type of object that will be passed with the event to subscribers. For this example it could be like this :
public class MyEventArgs{
public String Prop1 {get; set;}
}
Next fire it as-is in your class :
SomethingChanged?.Invoke(this, new MyEventArgs() { Prop1="test" });
Finnally handle it like this :
private void OnSomethingChanged(object sender, MyEventArgs e)
{
//TODO
}
NB You need to subscribe to the event in order to enter in the OnSometingChanged
method. Subscribe like this :
myClass.SomethingChanged+=OnSomethingChanged;
Where myClass
is an instance of the class where you define SomethingChanged