Я получаю ошибку e.PropertyChanged о том, что нет метода расширения и нет определения.Я новичок в такого рода материалах, поэтому я не знаю, как с этим справиться.Я пытаюсь создать свойство, которое будет использоваться, чтобы позволить пользователю выбирать разные месяцы для просмотра в каландре.
Ошибка возникает в следующем:
void MyViewModel_PropertyChanged(object src, PropertyChangedEventArgs e)
{
//error below for PropertyChanged
if (e.PropertyChanged = "NameofMonth")
{
var date = new DateTime(2011, NameofMonth, 1);
//LoadMonth(date);
}
}
--- Вотдва полных класса, с которыми он работает ---------
public class Schedule : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
private int MonthofYear = 6;
public int NameofMonth
{
get
{
return this.MonthofYear;
}
set
{
if (value != this.MonthofYear)
{
this.MonthofYear = value;
NotifyPropertyChanged("NameofMonth");
}
}
}
// public void UpdateCal(PropertyChangedEventArgs e)
// {
// if (PropertyChanged != null)
// PropertyChanged(this, e);
// }
public string MonthWeek { get; set; }
public string Year { get; set; }
public string Month { get; set; }
public string day { get; set; }
public string WeekOfYear { get; set; }
public string dayofweek { get; set; }
private int _weekno;
public int WeekNo {
get { return _weekno; }
set
{
if (Equals(_weekno, value)) return;
_weekno = value;
NotifyPropertyChanged("WeekNo");
}
}
private int _weekday ;
public int WeekDay
{
get { return _weekday; }
set
{
if (Equals(_weekday, value)) return;
_weekday = value;
NotifyPropertyChanged("WeekDay");
}
}
public Schedule()
{
PropertyChanged += MyViewModel_PropertyChanged;
}
void MyViewModel_PropertyChanged(object src, PropertyChangedEventArgs e)
{
if (e.PropertyChanged = "NameofMonth")
{
var date = new DateTime(2011, NameofMonth, 1);
//LoadMonth(date);
}
}
------ класс viewmodel ----------
public partial class SchedulePage : Page
{
public int pick2;
public event PropertyChangedEventHandler PropertyChanged;
MainWindow _parentForm;
public int pick;
Schedule sched = new Schedule();
static GregorianCalendar _gc = new GregorianCalendar();
public SchedulePage(MainWindow parentForm)
{
InitializeComponent();
// sched.PropertyChanged += MyViewModel_PropertyChanged;
sched.NameofMonth = comboMonth.SelectedIndex;
pick = Convert.ToInt32(comboMonth.SelectedItem);
_parentForm = parentForm;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
_parentForm.bindings.schedule.Clear();
var t = new List<Schedule>();
DateTime curr = DateTime.Now;
int jeez = listMe.SelectedIndex;
// comboMonth.Items.Add(curr.Month);
DateTime newcurr = new DateTime(2011, jeez+1, 1);
// pickdate = datePickercal.SelectedDate;
// DateTime newcurr = new DateTime(curr.Year, curr.Month, 1);
var cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
var ms = cal.GetWeekOfYear(new DateTime(newcurr.Year, newcurr.Month, 1), System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Sunday);
for (var i = 1; newcurr.Month == jeez+1; newcurr = newcurr.AddDays(1))
{
var month_week = (newcurr.Day / 7);
sched.MonthWeek = newcurr.GetWeekOfMonth().ToString();
sched.Month = newcurr.Month.ToString();
sched.Year = newcurr.Year.ToString();
sched.day = newcurr.Day.ToString();
sched.WeekOfYear = cal.GetWeekOfYear(newcurr, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString();
sched.dayofweek = newcurr.DayOfWeek.ToString();
t.Add(sched);
_parentForm.bindings.schedule.Add(new Schedule { WeekNo = newcurr.GetWeekOfMonth() - 1, WeekDay = (int)newcurr.DayOfWeek, day = newcurr.Day.ToString() });
}
lblDate.Content = (newcurr.Month - 1) + "/" + newcurr.Year;
//testGrid.ItemsSource = t;
comboMonth.DataContext = _parentForm.bindings;
DataContext = _parentForm.bindings;
}
}
}