How can I send variables by reference in an event handler method?
I've tried using a delegate to send it to another function that holds the variable I needed and it works. However, it creates a copy of the variable and and I can't change the value in the main class from the delegate function. I've then thought of moving the function to a class and store all the variables in the class so they can get and set. However, because it's a class and doesn't inherit the mainclass the WPF/XAML objects can't be found. I've tried inheriting the mainclass but because I'm creating the class inside the mainclass and that it is inheriting itself effectively it gets in a loop it can't escape.
public partial class MainWindow : Window
{
public class Program : MainWindow
{
public string Word { get; set; }
public void WhenPressed_1(object sender, RoutedEventArgs e)
{
lable_1.Content = Word;
}
}
public MainWindow()
{
InitializeComponent();
Program test = new Program();
Button_1.Click += delegate (object sender, RoutedEventArgs e) { test.WhenPressed_1(sender, e); };
}
}
It's at the line Program test = new Program(); it breaks.