Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How can I retrieve the actual children layout in a WrapPanel

 
 
Old 03-30-2006   #1 (permalink)
Jens


 
 

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 SpecsSystem Spec
Old 03-30-2006   #2 (permalink)
Drew Marsh


 
 

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 SpecsSystem Spec
Old 03-31-2006   #3 (permalink)
Jens


 
 

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 SpecsSystem Spec
Old 04-02-2006   #4 (permalink)
Ifeanyi Echeruo [MSFT]


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
New Christmas Song for Children Vista hardware & devices
Children of the Nile Vista Games
Those thieving children Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46