I currently use reflection to grab all the property names in a class of a specific type or access level. I then run these through RaisePropertyChanged() to essentially "update" the entire view.
An instance where I do this is on startup, when the program starts and when the ViewModel is instantiated it will run this to ensure the view is showing all the correct data from the model.
Is there anything wrong with doing this?
Code if you guys want it:
private void InitializeViewModel()
{
foreach (string name in MiscMethods.GetPropertyNames(this))
{
RaisePropertyChanged(name);
}
}
public static IEnumerable<string> GetPropertyNames(Object yourClass)
{
foreach (PropertyInfo property in GetProperties(yourClass))
{
yield return property.Name;
}
}
//Uses Reflection to return all properties in a class
private static IEnumerable<PropertyInfo> GetProperties(Object theObject)
{
return theObject.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance);
}