wpf - Get a rectangle of a newly added ListViewItem -
i add new record listview's itemssource collection:
source.add(newrecord); after action i'm trying rectangle of corresponding item:
listviewitem newitem = list.itemcontainergenerator.containerfromitem(newrecord) listviewitem; rect rc = layoutinformation.getlayoutslot(newitem); but, unfortunately, rc (0, 0, 0, 0). seems when call getlayoutslot method, new listviewitem not yet arranged. how can obtain correct information directly after adding new record?
any appreciated.
calling list.updatelayout(); before line listviewitem newitem = ... should rectangle immediately.
but generally, not recommend use updatelayout() anywhere in wpf program. layout procedures in wpf asynchronous performance reasons. therefore, better if program determined rectangles of list items @ later point in time.
here mean "later point in time":
source.add(newrecord); dispatcher.begininvoke(dispatcherpriority.loaded, new action(() => { listviewitem newitem = list.itemcontainergenerator.containerfromitem(newrecord) listviewitem; rect rc = layoutinformation.getlayoutslot(newitem); system.diagnostics.debug.writeline("rc = " + rc); }));
Comments
Post a Comment