Is it wrong to use RaisePropertyChanged () on every property in my ViewModel when I need to "refresh" or "refresh" the view?

I am currently using reflection to capture all property names in a class of a particular type or access level. I then run them through RaisePropertyChanged () to substantially update the entire view.

The instance where I am doing this is at startup, when the program starts up and when the ViewModel instance is instantiated, it runs this to ensure that the view shows all the correct data from the model.

Is there something wrong with this?

Code if you 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);
    }

      

+3


source to share


2 answers


Empty string event

RaisePropertyChanged("");

      



this will update all properties .

+6


source


Awful idea. A) reflection is slow, you don't even cache stuff B) why would you update 50 properties when you only update 1?



0


source







All Articles