c# - How to avoid that WPF ListBox updates block buttons? -
i have wpf window listbox
, bound public observablecollection<string>
, being updated thread (backgroudworker
).
<listbox name="listbox" itemssource="{binding mycollection}" ... />
in same window have button
click handler:
<button content="close" click="button_logwindow_closebutton_click" ... />
this handler not called when click button while listbox being updated. although works when background thread has finished , listbox
not being updated more.
this looks me button click event being removed queue before it's handler can called. right?
do know how fix this?
it's hard without seeing code, gui thread busy updating listbox on every call observablecollection's add method mouse click event not handled.
if background thread using dispatcher.invoke or dispatcher.begininvoke add items observablecollection, can lower priority (to dispatcher.background, example) in order give click events chance handled.
you use observablecollection add range method raises inotifycollectionchanged.collectionchanged event once collection of items instead of each item. see this answer or microsoft's own bulkobservablecollection examples.
Comments
Post a Comment