layout - Avoid frequent updates in WPF custom control -


i writing custom control in wpf. control have several properties cause update of control's logical tree. there several methods of form:

private static void onxxxpropertychanged(dependencyobject obj, dependencypropertychangedeventargs e) {     ((mycontrol)obj).rebuildtree(); } 

suppose rebuildtree() method complex , lenghty , if users changes several properties, method called several times causing application slowdown , hanging.

i introduce beginupdate() , endupdate() methods in windows forms fashion (to ensure update called once), practice disouraged in wpf.

i know renderer have lower priority , flicker may not appear, still why spoil precious running time calling same update method multiple times?

is there official best practice on how make efficient update of multiple dependency properties (without updating entire control after setting each one)?

just set flag when of these properties change, , have refresh method queued dispatcher once.

private static void onxxxpropertychanged(dependencyobject obj, dependencypropertychangedeventargs e) {     ((mycontrol)obj).needsrefresh = true;     ((mycontrol)obj).onneedsrefresh(); }  void onneedsrefresh() {    dispatcher.begininvoke((action)(() =>    {      if (needsrefresh)      {         needsrefresh = false;         rebuildtree();      }   }),dispatcherpriority.contextidle); } 

this way, properties updated , dispatcher call begininvoke, set flag false , refresh once.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -