A partial fix for small numbers of items in Looping Listbox control from ShoppingCart example in SurfaceSDK
i noticed listbox control shoppingcart example place items out of reach, on right side, if there fewer items than needed span width of listbox. wanted share partial fix issue.
for reference, listbox @ bottom of image wpf control issue: http://msdn.microsoft.com/en-us/library/ee804834(v=surface.10).aspx
here link public skydrive folder details issue , fix images: http://cid-51a978e24eb84848.photos.live.com/browse.aspx/looping%20listbox%20explanation%20images
the fix inside loopingpanel class, line 601
// if items fit in viewport @ same time, disable scrolling , center items if (totalcontentwidth < viewport.width) {
extent = new size(totalcontentwidth, viewport.height); setviewport(0); firstitemoffset = ( viewport.width - totalcontentwidth ) / 2; // line fix canhorizontallyscroll = false; }
during runtime, field values try place extent, contains items, at far right of viewport. problem starts with the extent getting placed right edge aligning right edge of viewport. firstitemoffset will place the first item right of left-edge of extent.
the calculation given on line creates offset equal the width of the extent. result first item gets placed right of left-edge of extent, because offset width of extent, gets placed @ right end of extent.
the fix flip subtraction:
// if items fit in viewport @ same time, disable scrolling , center items if (totalcontentwidth < viewport.width) { extent = new size(totalcontentwidth, viewport.height); setviewport(0); firstitemoffset = ( totalcontentwidth - viewport.width ) / 2; canhorizontallyscroll = false; }
totalcontent must smaller viewport's width, result negative value. negative value the offset instead places first item left of left-edge of extent.
i haven't sat down run math, intial runs show items placed in viewable portion of listbox. however, still far-rightmost item off end of listbox if close having enough items fill width of listbox. @ least works small numbers of items.
i wanted share fix in case else had same trouble it. please post if comes full fix takes care of number of items approach width of listbox.
Other Forums > Surface Application Design and Development
Comments
Post a Comment