简体   繁体   English

如何在日历中捕获所选日期更改事件?

[英]How to catch the selected date changed event in calendar?

I need to fire the date selected by an user for perform a research in a database. 我需要触发用户选择的日期,以便在数据库中进行研究。 The caller class isn't the MainWindow class but rather an external class called Fixtures, and read objects GUI call the manufacturer via a variable. 调用者类不是MainWindow类,而是一个名为Fixtures的外部类,读取对象GUI通过变量调用制造商。 For example, in this case to access the calendar execute: 例如,在这种情况下访问日历执行:

MainWindow.AppWindow.Calendar;

How can I see if a date has been selected by a user? 如何查看用户是否选择了日期?

If you want to do something when selected date changes, the Calendar control has a SelectedDatesChanged event. 如果要在选定日期更改时执行某些操作,则Calendar控件具有SelectedDatesChanged事件。 Add an event handler method for this event. 为此事件添加事件处理程序方法。

XAML: XAML:

<Calendar SelectedDatesChanged="Calendar_OnSelectedDatesChanged"/>

Code behind: 代码背后:

private void Calendar_OnSelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
}

It sounds like your question might be around object scope in C#. 听起来你的问题可能是C#中的对象范围。 Needs further explanation 需要进一步解释

You might want to use a DatePicker instead of a Calendar and listen for the following event SelectedDateChanged. 您可能希望使用DatePicker而不是Calendar,并侦听以下事件SelectedDateChanged。

You could try and listen for the DisplayDateChanged event for the Calendar class and do something when the date changes. 您可以尝试监听Calendar类的DisplayDateChanged事件,并在日期更改时执行某些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM