I am having some trouble with initializing a new variable as the object being sent by the global property changed. I have two classes BeltConfiguration
and BeltProperty
(both classes have INotifyPropertyChanged
). I have a globalpropertychanged
method in the BeltConfiguration
class as seen here.
private void BeltProperty_GlobalPropertyChanged(object sender, PropertyChangedEventArgs e)
{
BeltProperty validBelt = sender as BeltProperty;
if (validBelt != null)
{
this.Validation = validBelt.Validation;
}
switch (e.PropertyName)
{
case "Value":
this.Validation.ValidState = ConfigurationValid.Unknown;
OnPropertyChanged("Validate");
break;
case "ConfigurationInvalid":
this.Validation.ValidState = ConfigurationValid.False;
OnPropertyChanged("Validate");
break;
}
}
In the BeltProperty
class, I call this with OnGlobalPropertyChanged("ConfigurationInvalid");
However, when I call it, no matter what I do, validBelt
always results in being null
. I looked at the object sender by stepping through the code and it says that the declaring method, GenericParametersAttributes
, and GenericParametersPosition
threw an exception of System.InvalidOperationException
. I don't know if that has anything to do with why validBelt
won't accept sender as BeltProperty
. Thanks for any help or advice you can give me.
This is where I called BeltProperty_GlobalPropertyChanged in the Belt Property class.
private ConfigurationValidation _Validation = new ConfigurationValidation(ConfigurationValid.Unknown, "", "", null);
/// <summary>
/// Stores information as to wether this belt property is valid or invalid, and the details.
/// </summary>
internal ConfigurationValidation Validation
{
get { return _Validation; }
set {
_Validation = value;
if(_Validation.ValidState == ConfigurationValid.False)
{
OnGlobalPropertyChanged("ConfigurationInvalid");
}
}
}
/// <summary>
/// A global on property change that runs for any instantiated object of this type.
/// </summary>
/// <param name="name"></param>
static void OnGlobalPropertyChanged(string name)
{
GlobalPropertyChanged(
typeof(BeltProperty),
new PropertyChangedEventArgs(name));
}