-1

in my tool I create a TimePicker XAML control while runtime, but I'm struggling with the TimeChanged Event.

// TimePicker
TimePicker timePicker = new TimePicker
{
    Margin = new Thickness(0, 0, 0, 7),
    HorizontalAlignment = HorizontalAlignment.Center,
    VerticalAlignment = VerticalAlignment.Bottom,
    RequestedTheme = ElementTheme.Dark,
    Name = "Schedule_" + lightnumber + "_timepicker",
    ClockIdentifier = "24HourClock",
    Time = TimeSpan.Parse(hue_schedules_localtime),
};
hueGrid.Children.Add(timePicker);
timePicker.TimeChanged += new TimePickerValueChangedEventArgs(Schedule_TimeChange);

private void Schedule_TimeChange(string sender, TimePickerValueChangedEventArgs e)
        {

        }

I always get this error message "Error CS1729 'TimePickerValueChangedEventArgs' does not contain a constructor that takes 1 arguments"

Unfortunately I didn't found an c# example on the internet.

Can somebody please help me with this problem.

adi
  • 19
  • 4
  • Wrong type, TimeChanged is an event, not an event argument. It needs `new EventHandler(....)`. But just let the C# compiler figure that out by itself: `timePicker.TimeChanged += Schedule_TimeChange;` – Hans Passant Oct 20 '18 at 14:48

1 Answers1

2

You have a mistake in subscribing event code, you should add method/local function/lambda as subscriber, while you're trying to add TimePickerValueChangedEventArgs instance as subscriber instead, and TimePickerValueChangedEventArgs constructor doesn't accept one parameter, so that's why you got TimePickerValueChangedEventArgs does not contain a constructor that takes 1 arguments error. Fixed code:

timePicker.TimeChanged += Schedule_TimeChange;

private void Schedule_TimeChange(object sender, TimePickerValueChangedEventArgs e)
{

}
ingvar
  • 4,169
  • 4
  • 16
  • 29