I have a bizarre problem with a simple class that has 3 public properties. For some reason, only 2 of the properties "exist" even though the code that defines them is identical.
Elsewhere in the code I'm binding to these 3 properties, 2 of the properties work (metric & weightUnits), but "distanceUnits" does not.
When I put a breakpoint on the code where this class is instantiated, and hover over the object, only "metric" and "weightUnits" show up as public properties and when I expand "non-public members", everything is there but "distanceUnits" is still missing.
Debugger screen shot:
public class AppGlobalSettings : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private bool _metric;
public bool metric
{
get { return _metric; }
set {
_metric = value;
if (_metric) {
distanceUnits = "cm";
weightUnits = "Kg";
}
else {
distanceUnits = "in.";
weightUnits = "lbs";
}
OnPropertyChanged();
}
}
private string _weightUnits;
public string weightUnits { get { return _weightUnits; } set { _weightUnits = value; OnPropertyChanged(); } }
private string _distanceUnits;
public string distanceUnits { get { return _distanceUnits; } set { _distanceUnits = value; OnPropertyChanged(); } }
...
}
The only wrinkle I can think of is that the object is instantiated as "public static (see below), but that wouldn't explain why only some properties are available...
public class App : Application
{
public static AppGlobalSettings appSettings;
public App() {
appSettings = new AppGlobalSettings();
appSettings.distanceUnits = "in."; // ** just for debugging **
...
}
I know the property "exists" and is public because I put in debugging code (as noted above) and it works (it does indeed call the "set" method of "distanceUnits") but it does not show up in the debugger and the binding doesn't work.
For the sake of completeness, here is the binding code for the labels that shows distanceUnits:
Binding girthUnitBinding = new Binding("distanceUnits");
girthUnitBinding.Source = App.appSettings;
girthCell.unitLabel.SetBinding(Label.TextProperty, girthUnitBinding);
And in that section, if I edit "distanceUnits" to "weightUnits" just as a test, the binding works.
So any idea why the propertyChanged handler and the debugger can see "weightUnits" but not "distanceUnits" ?