简体   繁体   中英

PropertyChangedEventArgs error

I'm getting a e.PropertyChanged error saying there's no exstension method and no definition. I'm new to this kind of material so I'm not how to handle this. I'm trying to make a property that will be used to let the user select different months to view on a calender.

The error occurs in this:

    void MyViewModel_PropertyChanged(object src, PropertyChangedEventArgs e)
    {
        //error below for PropertyChanged
        if (e.PropertyChanged = "NameofMonth")
        {
            var date = new DateTime(2011, NameofMonth, 1);
            //LoadMonth(date);
        }
    }

---Heres the full two classes that its working with---------

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);
        }
    }

------the viewmodel class----------

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;

       }
   }
}
  1. That is an assignment ( e.PropertyChanged = "NameofMonth" ), you probably want == .

  2. As the warning correctly states there is no such property, see the docs . What you want is PropertyChangedEventArgs.PropertyName .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM