Question

I am sitting with a scenario where I believe my system is starting to hit scaling issues and I believe it stems from not doing something "the right way"

Essentially I have a Silverlight project and in this particular domain my models have a lot of dependencies

    int _Weight;
    public int Weight
    {
        get { return _Weight; }
        set
        {
            if (value != _Weight)
            {
                _Weight = value;
                RaisePropertyChanged("Weight");
            }
        }
    }

Then on the outside of that model, my app also chains an extra event onto the propertyChanged event as follows

myObject.PropertyChanged += UpdateUI;

my UpdateUI does a bunch of graphic stuff, generates images things that binding wont cater for.

and this works nicely.

but now suppose my Weight property, also has an effect on other properties, those will also fire off their PropertyChanged events (as they should, so all ui fields bound to those properties get updated), but then it will also cause UpdateUI to be fired off every time.

Meaning that if a property also affects 3 other properties, UpdateUI will fire 4 times when it only really needs to be fired after the last property.

It doesn't break anything, just feels that inefficient and architecture incorrectly.

So essentially what I am asking is, how can I get it that my UpdateUI only triggers off once per series of property changes

Thanks

Était-ce utile?

La solution

Not knowing your architecture I have two ides.

  1. This is what I would choose, but requires more effort - Design your UpdateUI method so that It can update according to the changed property, not simply refresh the whole UI when one property of one of hundreds ViewModels changes. For example if Age of a PersonViewModel changes, update only that.
  2. Execute pending layout updates once a few seconds. For example, you can start some sort of a timer which will check if there are pending layout updates (you will have to architecture that yourself) and execute them, or the last of them, depends on you. This can be efficient but must be designed carefully.

I am not familiar with Silverlight, only WPF, but I guess the same principles apply.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top