![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | How can I retrieve the actual children layout in a WrapPanel Hi all, I have a Wrap Panel and a collection of children flowing left to right and top to bottom. Depending on the actual width (determined by user scrolling) of the panel the children are layouted dynamically one-column or two column and so on. Item height and width may vary from child to child. So far all is fine, now here is my problem. The number of childen may be very high so I would like that only visible items are actually drawn (filled with images). To find out what items are actually visible I need a way to ask the wrap panel about the actual layout, something like Rows and Columns attributes in a grid with the difference that each row may have a different number of columns and that these collections are only valid until the WrapPanel is resized. I can't find any mechanism to ask the WrapPanel about the current layout. Is there any way to get this information or any other way to find out which elements are actually visible? Thanks Jens |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: How can I retrieve the actual children layout in a WrapPanel Jens wrote: > I have a Wrap Panel and a collection of children flowing left to right > and > top to bottom. Depending on the actual width (determined by user > scrolling) > of the panel the children are layouted dynamically one-column or two > column > and so on. Item height and width may vary from child to child. > So far all is fine, now here is my problem. The number of childen may > be very high so I would like that only visible items are actually > drawn (filled with images). To find out what items are actually > visible I need a way to ask the wrap panel about the actual layout, > something like Rows and Columns attributes in a grid with the > difference that each row may have a different number of columns and > that these collections are only valid until the WrapPanel is resized. > I can't find any mechanism to ask the WrapPanel about the current > layout. Is there any way to get this information or any other way to > find out which elements are actually visible? What you're talking about is refered to UI virtualization. There is a built in Panel type provided by the runtime called VirtualizingStackPanel, however, as you can probably tell by it's name, it's using the same layout logic as StackPanel. Since you want WrapPanel layout logic, you'll probably have to resort to writing your own VirtualizingPanel[1] subclass that mimics the logic of WrapPanel. Implementing a VirtualizingPanel is not exactly trivial, but luckily Dan Crevier has put up a nice four part blog series on how to go about doing it. HTH, Drew [1] http://windowssdk.msdn.microsoft.com...izingPanel.asp [2] http://blogs.msdn.com/dancre/archive...06/526310.aspx ___________________________________ Drew Marsh Chief Software Architect Mimeo.com, Inc. - http://www.mimeo.com Microsoft C# / WPF MVP Weblog - http://blog.hackedbrain.com/ |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: How can I retrieve the actual children layout in a WrapPanel Hi Drew, thanks a lot for this answer. It appears that I still have to learn a lot ;-) What currently confuses me a bit is that the behavior of WrapPanel is fine for me. I just would neet an additional member function/property. Maybe you take this just as a hint for upcoming interface reviews. But before continueing this discussion I should read this article. Jens "Drew Marsh" wrote: > What you're talking about is refered to UI virtualization. There is a built > in Panel type provided by the runtime called VirtualizingStackPanel, however, > as you can probably tell by it's name, it's using the same layout logic as > StackPanel. Since you want WrapPanel layout logic, you'll probably have to > resort to writing your own VirtualizingPanel[1] subclass that mimics the > logic of WrapPanel. Implementing a VirtualizingPanel is not exactly trivial, > but luckily Dan Crevier has put up a nice four part blog series on how to > go about doing it. > > HTH, > Drew > > [1] http://windowssdk.msdn.microsoft.com...izingPanel.asp > [2] http://blogs.msdn.com/dancre/archive...06/526310.aspx > > ___________________________________ > Drew Marsh > Chief Software Architect > Mimeo.com, Inc. - http://www.mimeo.com > Microsoft C# / WPF MVP > Weblog - http://blog.hackedbrain.com/ > > > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: How can I retrieve the actual children layout in a WrapPanel The short answer: I believe WrapPanel already does this for you. We put a lot of effort in making sure our built in panels do the least amount of work and for that reason WrapPanel shouldnt call measure or arrange on items that wont be visible and an item isn't rendered until it has been arranged. For most normal panels (Wrap, Stack, Dock) your performance should only deteriorate in terms of visible items. Caveat emptor: By design a ScrollViewer parent may cause a panel to measure\arrange items than will not be visible. Only VirtualizingPanels are smart enough to deal with this scenario. VirtualizingStackPanel is the only built in virtualizing panel in the platform. Additionaly VirtualizingPanels can pull in only resources needed for visible items which should buy you working set wins. Probably more detail than you wanted : Layout and rendering in WPF are a tree part dance. A parent asks its children what size they want to be given a space constraint (Measure) Good parents do the best they can given constraints to place their children in appropriate places (Arrange) The child renders in its arranged location The layout logic for markup of the form <Window> <WrapPanel> <Child1 /> ... </ChildN /> </WrapPanel> </Window> Window Measure Window determines an arbitrary size (100x100) and asks WrapPanel to measure with an 80x80 constraint. We are pretending Window needs a 10px padding WrapPanel Measure WrapPanel measures each child in turn with an 80x80 constraint and each child returns its desired size WrapPanel stops measuring children when it becomes obvious that the next child will be placed outside the 80x80 constraint. In essence wrap panel is measuring and precomputing arrange. WrapPanel returns a desired size of 80x80 Window Arrange Window arranges WrapPanel at 10,10 (remember the 10px padding) with its desired size (80x80) WrapPanel Arrange For each row WrapPanel arranges each child in turn at the width they desired and at the height of the tallest item on that row. Wrap panel stops arranging when it becomes obvious that the next child will be placed outside the 80x80 arrange box. Window Render Window renders its chrome and asks its child to render WrapPanel Render WrapPanel renders its chrome (border, background that kind of stuff) and asks each of its arranged children to render. Remember an item that has not been arranged will not be rendered -- Ifeanyi Echeruo [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights. "Jens" <Jens@discussions.microsoft.com> wrote in message news:60AF1CBB-3011-4E83-80C7-5A4D3116456D@microsoft.com... > Hi all, > I have a Wrap Panel and a collection of children flowing left to right and > top to bottom. Depending on the actual width (determined by user > scrolling) > of the panel the children are layouted dynamically one-column or two > column > and so on. Item height and width may vary from child to child. > > So far all is fine, now here is my problem. The number of childen may be > very high so I would like that only visible items are actually drawn > (filled > with images). To find out what items are actually visible I need a way to > ask > the wrap panel about the actual layout, something like Rows and Columns > attributes in a grid with the difference that each row may have a > different > number of columns and that these collections are only valid until the > WrapPanel is resized. I can't find any mechanism to ask the WrapPanel > about > the current layout. Is there any way to get this information or any other > way > to find out which elements are actually visible? > > Thanks Jens |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New Christmas Song for Children | Malke | Vista General | 0 | 11-29-2007 06:45 AM |
| How do you retrieve the actual value displayed in a ListView/GridView after binding and converting? | Martin | Avalon | 0 | 10-29-2007 08:55 AM |
| ScrollViewer breaks my WrapPanel | steve | Avalon | 3 | 04-06-2007 06:27 PM |
| Children of the Nile | seasider | Vista Games | 0 | 03-18-2007 02:34 PM |
| Those thieving children | MICHAEL | Vista General | 2 | 12-31-2006 12:58 PM |