我收到一个e.PropertyChanged错误,说没有exstension方法,也没有定义。我是这种材料的新手,所以我不知道如何处理这个问题。我正在尝试创建一个属性,用于让用户选择不同月份在日历上查看。
错误发生在:
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;
}
}
}
答案 0 :(得分:3)
这是一项作业(e.PropertyChanged = "NameofMonth"
),您可能需要==
。
由于警告正确说明没有此类属性,请参阅docs。你想要的是PropertyChangedEventArgs.PropertyName
。