Pergunta

In my wpf application, I've MonthView class where this method is defined, which takes selected date from the calendar and shows respective dayView window for that date.

public void calItemSelectedDate(object sender, SelectionChangedEventArgs e)
    {
        DateTime d;
        if (sender is DateTime)
        {
            d = (DateTime)sender;
        }
        else
        {
            DateTime.TryParse(sender.ToString(), out d);
        }
        DayView Activity = new DayView(d);
        Activity.Show();
        this.Hide();
     }

Now, In my CustomView class, I've created instance of dayView where I want to pass selected date.

DateTime p = Globals._globalController.getMonthViewWindow.calItemSelectedDate(object s, EventArgs e); // here it shows error
DayView d = new DayView(DateTime p);

so, please suggest ways to call that 'calItemSelectedDate' method so I can pass appropriate datetime parameter to my DayView.

Foi útil?

Solução

The method to refering to is an event handler and not a best choice for direct calling. What I would do in this case, is :

//A PROPERTY THAT SAVES SELECTED DATE VALUE
public DateTime SelectedDate {get;set;}

//A METHOD THAT SHOWS ACTIVITY 
public void ShowActivity(DateTime date) {
    DayView Activity = new DayView(date);
    Activity.Show();
    this.Hide();
}

public void calItemSelectedDate(object sender, SelectionChangedEventArgs e)
{
    DateTime d;
    if (sender is DateTime)
    {
        d = (DateTime)sender;
    }
    else
    {
        DateTime.TryParse(sender.ToString(), out d);
    }

    SelectedDate = d;

    ShowActivity(d);
 }

and from your class where you want to call it:

DateTime p = Globals._globalController.getMonthViewWindow.SelectedDate;
DayView d = new DayView(p);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top