What I want is to store a method with parameters owned by one class in a variable in another class for later execution. The first class would be my MainWindow class and second is a UserControl. The method I want to pass would stand in as a SelectionChanged event for a ListBox contained in the UserControl. The method would require a parameter only the UserControl will know at the time items are changing.
An example for my method (in MainWindow) would be as follows:
public void MethodToPass(string UniqueParameterValue) {
//...do stuff with special string
}
And I would pass the method in my MainWindow class like:
//In MainWindow.Loaded
this.userControlInstance.SelectionChanged += MethodToPass;
Because I'm not directly assigning it to the ListBox, I would do so in the UserControl like:
private void selectionChanged;
public void SelectionChanged {
get {
...
}
set
{
this.selectionChanged = value;
this.listBox1.SelectionChanged += value;
}
}
I feel like NOT directly setting the ListBox is redundant, but my MainWindow class does not allow me to "see" it. I also feel like the more politically correct way to do this is to store the method in a variable, but I don't know how to do that or call it.
How are operations like this usually done?