在我的工具中,我在运行时创建了一个TimePicker XAML控件,但是我在为TimeChanged事件苦苦挣扎。
// 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)
{
}
我总是收到此错误消息“错误CS1729'TimePickerValueChangedEventArgs'不包含带有1个参数的构造函数”
不幸的是,我在互联网上找不到c#示例。
有人可以帮我解决这个问题。
答案 0 :(得分:2)
您在订阅事件代码时出错,您应将方法/本地函数/ lambda添加为订户,而您尝试将TimePickerValueChangedEventArgs
实例添加为订户,而TimePickerValueChangedEventArgs
构造函数却没有。 t接受一个参数,所以这就是为什么出现TimePickerValueChangedEventArgs does not contain a constructor that takes 1 arguments
错误的原因。固定代码:
timePicker.TimeChanged += Schedule_TimeChange;
private void Schedule_TimeChange(object sender, TimePickerValueChangedEventArgs e)
{
}