Firstly I am not a C# developer, although I have plenty of programming in my past, but it's all pre .NET days, so please go easy :-)
So I have a little WPF app that I am trying to create. I want to run some methods, I think that's what they're called. (I would have called them a function back in my day). Now I want those methods to report back to a listbox on the main GUI for the app.
After a bit of digging I have found a way, but I don't think it's really very neat and seems wrong somehow, although it works.
I have a basic WPF form, one button and one listbox. When you click the button it calls the button event and then runs the method and updates the listbox.
If I have several other buttons doing other jobs, do I have to re-create the "SomeOtherCode.LogHandler myLogger = new SomeOtherCode.LogHandler(L
ogger);" and pass the myLogger through to the method each time?
It seems mad to me that you would have to do this, and I'm sure that's it's just my inexperience that's holding me back. Can anyone shed a little light on this?
There is another issue in that the listbox doesn't update until you are out of the method you're calling, so it's hard to really track progress within a method. I've started to look at data binding of the listbox, but I haven't researched it much yet. I'm open to suggestions on how to Log events to the UI.
Many Thanks, Mike...
*** Window1.xaml.cs ***
/// Interaction logic for Window1.xaml
public partial class Window1 : Window
SomeOtherCode SOC = new SomeOtherCode();
private void btn_Connect_Click(object sender, RoutedEventArgs e)
listBox1.Items.Add("About to run method? in a class");
SomeOtherCode.LogHandler myLogger = new SomeOtherCode.LogHandler(Logger);
public void Logger(string updateWith)
*** OtherFile.cs ***
public delegate void LogHandler(string updateWith);
public void ConnectToSomething(LogHandler logHandler)
logHandler("Report on Progress");
//Some more code