I am using SimpleMVVM and have two separate classes (models), one using the second like this:
public class Database : ModelBase<Database>
{
public String ServerName //{ get; set; }
{
get { return _ServerName; }
set
{
if (_ServerName != value)
{
_ServerName = value;
NotifyPropertyChanged(m => m.ServerName);
}
}
}
private String _ServerName = "MyTestServer";
// other properties removed for brevity
}
public class MyConfiguration
{
/// <summary>
/// Database information
/// </summary>
public Database DatabaseInfo
{
get { return _DatabaseInfo; }
set
{
if (_DatabaseInfo != value)
{
_DatabaseInfo = value;
NotifyPropertyChanged(m => m.DatabaseInfo);
}
}
}
private Database _DatabaseInfo = new Database();
}
When 'ServerName'
is changed, the NotifyPropertyChanged(m => m.ServerName);
command executes but NOT NotifyPropertyChanged(m => m.DatabaseInfo);
How do I make the NotifyPropertyChanged(m => m.DatabaseInfo);
fire whenever one of the properties of Database
changes?
You can use the
PropertyChanged
event of theINotifyPropertyChanged
interface to tell you when the child property changes.In your
MyConfiguration
class:...
Please note that you will need to attach this listener each time that you change the
DatabaseInfo
property value. Also, note that if you just wanted to listen to one property, then you could have done this: