c# - WPF how to wait for binding update to occur before processing more code? -
as understand dispatcher takes place in thread, takes care of updating data bindings, layout, etc. however, there way wait until dispatcher has no more items or @ least no more data bindings? want ensure property change has updated of components , run dependent property changed callbacks before running more code.
edit: guessing not needed, trying understand should have done instead. main question @ wpf if children of scrollviewer resize, scrollviewer automatically update extent?
but curious whether wait bindings update or if there guarantee 1 binding updates before another? expected code such order of binding updates not matter? used dependency property changed callback's perform various stuff dependent on other properties updating
the dispatcher has several priorities processing single tasks. i'm quite sure cannot change priority of callbacks of dependency properties. if changed data binding, in queue dispatcherpriority.databinding priority. manipulate values of dependency properties cause layout/other dependency properties change. , want wait after first manipulation until these layout updates/changes processed , current ui state?
winforms had doevents function such cases causes ui events being processed before normal code execution continues. wpf has no such builtin function can write own doevents:
public static void doevents() { if (application.current == null) return; application.current.dispatcher.invoke(dispatcherpriority.background, (delegate) (() => {})); }
the empty delegate invoked synchronously, means call returns after delegate executed dispatcher. dispatcherpriority.background low priority dispatcher call processed after example data bindings, layout updates or rendering. http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherpriority.aspx
so call doevents() after first manipulation of dependency properties , before want read other dependency properties , should done.
Comments
Post a Comment