I am creating a Windows Phone application and I cannot create a dynamically created Button with its event handler.
Code I use:
public partial class MainPage : PhoneApplicationPage
{
Button AddButton
public MainPage()
{
CreateInterestEntry();
}
private void CreateInterestEntry()
{
EntrySegment = getEntrySegment();
ContentPanel.Children.Add(EntrySegment);
}
private void AddButton_Click(Object sender, RoutedEventArgs e)
{
}
private Grid getEntrySegment()
{
Grid EntrySegment = new Grid();
AddButton = new Button();
AddButton.Content = "Add";
AddButton.Click += new EventHandler(AddButton_Click);
return EntrySegment;
}
}
}
Using this code, he complains that no overload for AddButton_Click matches the delegate "System.EventHandler".
It is almost identical to the code under the examples here in msdn, except that I changed the argument type in AddButton_Click from EventArgs to RoutedEventArgs since otherwise Visual Studio tells me that it cannot implicitly convert from System.EventHandler to System.RoutedEventHandler.
Thanks in advance
source
share