可以执行以下操作:
// Add two event handler for the button click event
button1.Click += new RoutedEventHandler(button1_Click_1);
button1.Click += new RoutedEventHandler(button1_Click_2);
但是如何在XAML中为按钮的点击事件添加多个事件处理程序? 谢谢你的提示!
答案 0 :(得分:8)
您无法在XAML中订阅多个事件处理程序。但是,您可以通过订阅单个事件处理程序然后从事件处理程序调用两个或更多方法来实现相同的效果。
private void Button_OnClick(object sender, RoutedEventArgs e)
{
ButtonOnClick1();
ButtonOnClick2();
}
private void ButtonOnClick1()
{
//Do something...
}
private void ButtonOnClick2()
{
//Do something...
}
答案 1 :(得分:1)
您可以在protected $dates = ['date_from', 'date_to'];
中指定多个处理程序,如下所示:
$min_date = Reservation::select(DB::raw('MIN(date_from) as min'))->first();
$max_date = Reservation::select(DB::raw('MIN(date_to) as max'))->first();
$data = [];
if (!is_null($min_date) && !is_null($max_date)) {
$daterange = new DatePeriod(DateTime::createFromFormat('Y-m-d H:i:s', $min_date->min), new DateInterval('P1D') ,DateTime::createFromFormat('Y-m-d H:i:s', $max_date->max));
$reservations = Reservation::all();
foreach ($daterange as $date) {
$data[$date->format('Y-m-d')] = $reservations->filter(function($reservation) use($date) {
$carbon_date = Carbon::instance($date)->endOfDay();
return ($reservation->date_from->startOfDay()->lte($carbon_date) && $reservation->date_to->endOfDay()->gte($carbon_date));
})
->count();
}
}