Search code examples
c#wpf

Button Click Callbacks


I have a couple of user controls that are loaded at runtime that contain a bunch of buttons. I register those button click events in my data class by getting a reference to the user control. This is how I'm doing it now in my data class:

MainWindow.Instance.Menu1Instance.Button1.Click += new RoutedEventHandler(Button1_Click);

Problem is I'm going to have several user controls that need references and it seems kind of tedious. I was wondering if there was a better way of doing this?


Solution

  • You could use data binding, see ICommand is like a chocolate cake.