I'm building out a simple ToDoList app using C# and WPF. The goal is that when the button is clicked. The text in a TextBox will be added as a new element in a List which is an existing object instance.
To do this I've updated the Button click event handler's signature to include a parameter to pass the List object. When I compile this code I get an error thrown from my XAML file at the line which contains the Click="AddTaskButton_Click"
Error: No overload for 'AddTaskButton_Click' matches delegate 'RoutedEventHandler'
What could be throwing this error? I've seen other code samples where this compiles fine. Is there another way to accomplish passing "data" or an object to an event handler in WPF? I'm new to WPF.
XAML
<Button
x:Name="AddTaskButton" Content="+ Add"
Click="AddTaskButton_Click">
</Button>
Backend C#
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<string> taskList = new Tasklist {"Task A", "Task B", "Task C"}
AddTaskButton.Click += (object sender, RoutedEventArgs e) => { AddTaskButton_Click(sender, e, taskList); };
}
private void AddTaskButton_Click(object sender, RoutedEventArgs e, List<string> taskList)
{
// do something
}
}
Tasklistwith a capitalTand a littlel?