473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Implementation of Binding complier error

I am attempting to use binding in creating a win7Phone application
I get the error:
An object reference is required for the non-static field, method or property 'MyCode.myClass.NotifyPropertyChanged(string)'
on Line 15.

Does anybody know where I went astray??
Thanks for any assistance

Expand|Select|Wrap|Line Numbers
  1. namespace MyCode
  2. {
  3.    public class myClass : INotifyPropertyChanged
  4.     {
  5.         private static string productNumber;
  6.  
  7.         public static string ProductNumber
  8.         {
  9.             get { return productNumber; }
  10.             set
  11.             {
  12.                 if (!object.Equals(value, productNumber))
  13.                 {
  14.                     productNumber = value;
  15.                     NotifyPropertyChanged("IOA_ProdNum");
  16.                 }
  17.             }
  18.         }
  19.         public event PropertyChangedEventHandler PropertyChanged;
  20.         protected void NotifyPropertyChanged(string propertyName)
  21.         {
  22.             PropertyChangedEventHandler handler = this.PropertyChanged;
  23.             if (null != handler)
  24.                 handler(this, new PropertyChangedEventArgs(propertyName));
  25.         }
  26.     }
  27. }
  28.  
Oct 21 '10 #1
5 1195
Curtis Rutland
3,256 Expert 2GB
You can't call a non-static resource (method/property/field) from a static one.
Oct 21 '10 #2
I tried this. And it just moved the problem elsewhere.
Boy, I sure have my problems:
Now 'this' has the error
Keyword 'this' is not valid in a static property, static method or static field initializer

Expand|Select|Wrap|Line Numbers
  1.  public class myClass: INotifyPropertyChanged
  2.     {
  3.         private static string productNumber;
  4.  
  5.         public static string ProductNumber
  6.         {
  7.             get { return productNumber; }
  8.             set
  9.             {
  10.                 if (!object.Equals(value, productNumber))
  11.                 {
  12.                     productNumber = value;
  13.                     NotifyPropertyChanged("IOA_ProdNum");
  14.                 }
  15.             }
  16.         }
  17.         public event PropertyChangedEventHandler PropertyChanged;
  18.         private static void NotifyPropertyChanged(string propertyName)
  19.         {
  20.             PropertyChangedEventHandler handler = this.PropertyChanged;
  21.             if (null != handler)
  22.                 handler(this, new PropertyChangedEventArgs(propertyName));
  23.         }
  24.     }
  25.  
Oct 21 '10 #3
Curtis Rutland
3,256 Expert 2GB
That's really the key problem, trying to implement INotifyPropertyChanged on static properties. I suggest you try googling "INotifyPropertyChanged static" and see what some others have to say about it. There's discussions about it out there.
Oct 22 '10 #4
hype261
207 100+
The reason you are getting an error is because the handler expects a this pointer on this line.

Expand|Select|Wrap|Line Numbers
  1. handler(this, new PropertyChangedEventArgs(propertyName));
Static methods and variables don't have a this pointer because they exist at class scope instead of instance scope.

PropertyChangedEventHandler expects an Object sender and PropertyChangedEventArgs e in its arguments. You may be able to use NULL for the sender or another dummy argument to get around this.
Oct 22 '10 #5
Curtis Rutland
3,256 Expert 2GB
If you used null, Observable Collections (or anything else that subscribes) wouldn't know which item in the collection changed.
Oct 22 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Aman | last post by:
Hi, could you please tell me why the following program gives a compilation error ? what does this error mean ? note also that when i derefernce the iterator , the contents are displayed. int...
0
by: Francisco J. Reyes | last post by:
I get an Internal complier error when compiling C# windows project that uses a custom Class add as reference to the project. The problem appears to be related to the ENUM type used in the class...
3
by: Balaji | last post by:
I'm trying to do some basic socket programming. here is the line of code which is creating problem.. int FAR PASCAL __declspec (dllexport)(char * addr,int port) Hers is the error I'm...
2
by: Sen | last post by:
Hi All, I am using (Visual C++ 1.52 IDE )for my MFC Application Project. I am working on an existing code base where the no of lines is around 100,000, spread across different header and cpp...
3
by: Dean Slindee | last post by:
Not sure how to fix this syntax error when Option Strict On is enforced. Can anyone help? Dim ctl As Control Dim sa() As String For Each ctl In pnlParameter.Controls sa =...
1
by: William | last post by:
I am using mingw and msys, there is a complier error: c:/cpp/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/basic_ios.h: In instantiation of `std::basic_ios<wchar_t,...
0
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application)....
1
by: John Kotuby | last post by:
Hi all. I am using VS 2005 and VB.NET. Lately as my Web Application is getting larger, I have been getting strange compiler messages like the following: --------------------------- Compiler...
0
by: Armin Zingler | last post by:
<Just_a_fan@home.netschrieb After having longer discussions about a similar issue, I ask you to provide an example of the source and destination value(s) and their data types. Thanks. Example...
1
by: yuniara | last post by:
Hi.. What are the programs or libraries use FEC for handling network packet error ? And how to implement this ? I'm using Ubuntu 8.04. Thank you
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.