wpf 如何在日历中捕捉选定的日期更改事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31742288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:18:51  来源:igfitidea点击:

How to catch the selected date changed event in calendar?

c#wpfcalendar

提问by Harold Finch

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. For example, in this case to access the calendar execute:

我需要触发用户选择的日期以在数据库中执行研究。调用者类不是 MainWindow 类,而是称为 Fixtures 的外部类,读取对象 GUI 通过变量调用制造商。例如,在这种情况下访问日历执行:

MainWindow.AppWindow.Calendar;

How can I see if a date has been selected by a user?

如何查看用户是否选择了日期?

采纳答案by Glen Thomas

If you want to do something when selected date changes, the Calendar control has a SelectedDatesChangedevent. Add an event handler method for this event.

如果您想在选定日期更改时执行某些操作,日历控件有一个SelectedDatesChanged事件。为此事件添加事件处理程序方法。

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#. Needs further explanation

听起来您的问题可能与 C# 中的对象范围有关。需要进一步解释

回答by Timeless

You might want to use a DatePickerinstead of a Calendar and listen for the following event SelectedDateChanged.

您可能希望使用DatePicker而不是 Calendar 并侦听以下事件 SelectedDateChanged。

You could try and listen for the DisplayDateChangedevent for the Calendar class and do something when the date changes.

您可以尝试侦听Calendar 类的DisplayDateChanged事件,并在日期更改时执行某些操作。