Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

Currently working on a Windows 8 app for an important client, I will be writing about small issues, tips and tricks, ideas and whatever occurs to me during the development and the integration of this app.

When working with a GridView, it is quite common to use a VariableSizedWrapGrid as the ItemsPanel. This creates a nice flowing layout which will auto-adapt for various resolutions.

Read the rest of this entry ยป

Print | posted on Saturday, September 1, 2012 3:19 PM

Feedback

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by Fernando at 9/3/2012 8:29 AM Gravatar
Nice article!

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by Jose Luis Latorre at 9/4/2012 7:16 AM Gravatar
Nice one Laurent, really like the trick!!

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by G Flexman at 9/4/2012 5:05 PM Gravatar
To change Column & Row Span at runtime you need to subclass the GridView and override PrepareContainerForItemOverride as there is no built in method to do this (as of yet).

It's then just a simple matter of setting the row & column span for each item.

VariableSizedWrapGrid.SetColumnSpan(element as UIElement, colVal);
VariableSizedWrapGrid.SetRowSpan(element as UIElement, rowVal);

base.PrepareContainerForItemOverride(element, item);

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by guzelevim at 9/8/2012 9:24 AM Gravatar
thanks for these useful knowledges.best wishes.

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by Fernando Urkijo Cereceda at 10/14/2012 2:54 PM Gravatar
If you need to change the style of the ItemContainerStyle dynamically, you can use this:

Style style = new Style() { TargetType=typeof(GridViewItem)};
style.Setters.Add(new Setter(VariableSizedWrapGrid.RowSpanProperty, rowSpan));
style.Setters.Add(new Setter(VariableSizedWrapGrid.VerticalAlignmentProperty, VerticalAlignment.Top));
style.Setters.Add(new Setter(VariableSizedWrapGrid.HorizontalAlignmentProperty, HorizontalAlignment.Left));

return style;

at the ItemContainerSelector

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by Design at 1/14/2013 11:52 AM Gravatar
Oh you have such a great time and from the pictures it seams that the places which you visited are absolutely incredible.

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by Ricardo at 1/21/2013 6:11 PM Gravatar
Nice article Laurent, always been a fan of MVVMLight

# re: Adventures in Windows 8: Placing items in a GridView with a ColumnSpan or RowSpan

left by Steve at 6/26/2013 5:04 PM Gravatar
I wish to say thank you for an exciting web site about a subject I have had an curiosity in for some time now...chexsystemsremovals.com
Comments have been closed on this topic.