?
Solved

Binding not working (NotifyPropertyChanged firing but PropertyChanged is null)

Posted on 2010-04-09
1
Medium Priority
?
2,055 Views
Last Modified: 2013-11-12
Hey, I'm suffering a strange case where just one of my bindings won't work. I'm not sure why it's failing but I think it has to do with the data structure I'm binding too.

My binding statement is this:
            <Label  x:Name="Cedent"  ...
                        Content="{Binding Source={x:Static Application.Current},
                                          Path=ExposureMetaDataList.TTProgramInfo.Cedent}" />

My App.cs class has a property called ExposureMetaDataList
This, in turn has a property called TTProgramInfo, which is also a data structure.
This class has one private variable which is a data structure ttProgramInfo, and 3 public prperties which expose three properties of that data structure. The one being accessed is:

        public string Cedent {
            get {
                return ttProgramInfo.Cedent;
            }
            set {
                ttProgramInfo.Cedent = value;
                NotifyPropertyChanged("Cedent");
            }
        }

When the property "Cedent" is changed, the set method gets called, as does NotifyPropertyChanged:

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(String propertyName)
        {
            if(PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

But when that function gets called, 'PropertyChanged' is null, and so nothing happens. Why is it null? For every other bound property, the PropertyChanged eventhandler is magically set to something, but not in this case. How can I figure this out?

Below is the code where the property gets set. Note that the data structure is being reset too (but this should not harm the binding since it's set in the XAML and the data structure is initialized dynamically anyways.
ttProgramInfo = new TTProgramInfoVM();
if(ds != null && ds.Tables[0].Rows.Count > 0)
{
    //TODO: None of these properties are firing approprate notify property change events.
     ttProgramInfo.TTID = Convert.ToInt32(ds.Tables[0].Rows[0]["TTID"]);
     ttProgramInfo.Cedent = (String) ds.Tables[0].Rows[0]["Cedent"];
     ttProgramInfo.CCY = (String) ds.Tables[0].Rows[0]["CCY"];
     ((QuartzShareUI.App) Application.Current).TTIDLoggedIn = true;
}

Open in new window

0
Comment
Question by:alainbryden
1 Comment
 
LVL 21

Accepted Solution

by:
alainbryden earned 0 total points
ID: 30208338
Ugh. Why does this always happen. I have a problem for 2 whole days, finally ask a question, and then solve it myself within an hour.

Turns out the reason was that in the above code, I was referring to the private local variable
private TTProgramInfoVM ttProgramInfo;
directly instead of using the public property I had created for it:
        public TTProgramInfoVM TTProgramInfo {
            get {
                return ttProgramInfo;
            }
            set  {
                ttProgramInfo = value;
                NotifyPropertyChanged("TTProgramInfo");
            }
        }

I had thought that since I was only looking for the property change events of the sub-properties of that data structure, that it wouldn't matter how I referenced that data structure.

Miraculously, the attached code solves the problem:

--
Alain
TTProgramInfo = new TTProgramInfoVM();
if(ds != null && ds.Tables[0].Rows.Count > 0)
{
    //TODO: None of these properties are firing approprate notify property change events.
     TTProgramInfo.TTID = Convert.ToInt32(ds.Tables[0].Rows[0]["TTID"]);
     TTProgramInfo.Cedent = (String) ds.Tables[0].Rows[0]["Cedent"];
     TTProgramInfo.CCY = (String) ds.Tables[0].Rows[0]["CCY"];
     ((QuartzShareUI.App) Application.Current).TTIDLoggedIn = true;
}

Open in new window

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month6 days, 14 hours left to enroll

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question