从发件人处获取选定日期

时间:2013-05-31 07:30:16

标签: c# calendar

我想从对象发件人那里获取所选日期,并将该日期传递给其他方法。那么,如何从发件人对象中获取日期。

我的C#代码;

  public partial class MonthView : MetroWindow
{
    AppController a=new AppController();


    public MonthView()
    {
        InitializeComponent();
        calMain.DisplayDate = DateTime.Today;
    }

    public void calItemSelectedDate(object sender, SelectionChangedEventArgs e)
    {
        //sender = calMain.SelectedDate;   
        //DateTime d = (DateTime)sender;
        //a.fetchAndPopulateForDate(d);            <------I want code here.
        //DayView Activity = new DayView();
        //Activity.Show();
        //this.Close();

    }

 }

1 个答案:

答案 0 :(得分:3)

sender始终是引发事件的控件。在这种情况下,它是Calendar。所以顺便说一句:

public void calItemSelectedDate(object sender, SelectionChangedEventArgs e)
{
    Calendar cal = (Calendar)sender; 
    DateTime d = cal.SelectedDate;
    a.fetchAndPopulateForDate(d); <------I want code here.
    // ...
}

(但是,既然你也可以通过calMain.SelectedDate直接访问它,我真的不明白这个问题)