In the code below, how do I modify the "Fifths" setter to trigger a property-changed event for the other property?
public class KeySignature: Csla.BusinessBase<KeySignature>
{
public static readonly Csla.PropertyInfo<int> FifthsProperty = RegisterProperty(new Csla.PropertyInfo<int>("Fifths", 0));
public int Fifths
{
get { return GetProperty(FifthsProperty); }
set { SetProperty(FifthsProperty, value); }
}
public enum KeySignatureNames { Cf = -7, Gf = -6, Df = -5, Af = -4, Ef = -3, Bf = -2, F = -1, C = 0, G = 1, D = 2, A = 3, E = 4, B = 5, Fs = 6, Cs = 7 }
public string Name
{
get
{
var ret = (KeySignatureNames)(Fifths % 8);
return ret.ToString();
}
}
}
Hi,
I prefer to have leave my property code a simple as can be so my preferred solution for your question here IMO is #2.
1. If Name is a registered property I'd prefer to use the Dependency business rule.(Not possible here)
BusinessRules.AddRule(new Dependency(FifthsProperty, NameProperty));
2. Override the OnPropertyChanged
protected override void OnPropertyChanged(string propertyName) { base.OnPropertyChanged(propertyName); if (propertyName == FifthsProperty.Name) { OnPropertyChanged("Name"); } }
3. Or you may call OnPropertyChanged in Fifths setter:
public static readonly Csla.PropertyInfo<int> FifthsProperty = RegisterProperty(new Csla.PropertyInfo<int>("Fifths", 0)); public int Fifths { get { return GetProperty(FifthsProperty); } set { SetProperty(FifthsProperty, value); OnPropertyChanged("Name"); } } public enum KeySignatureNames { Cf = -7, Gf = -6, Df = -5, Af = -4, Ef = -3, Bf = -2, F = -1, C = 0, G = 1, D = 2, A = 3, E = 4, B = 5, Fs = 6, Cs = 7 } public string Name { get { var ret = (KeySignatureNames)(Fifths % 8); return ret.ToString(); } }
Copyright (c) Marimer LLC