Reputation: 4566
I'm trying to add portrait support to a page containing a GridView
that uses a VirtualizingStackPanel
as its ItemsPanelTemplate
. The idea is that when the orientation changes, I'd be able to change the Orientation
property of the VirtualizingStackPanel
to scroll vertically in portrait and horizontally in landscape. However, since the VirtualizingStackPanel
is used as a template, I can't directly access it by name in the code behind.
Is there any way to accomplish what I want?
I could just make a duplicate of the GridView
(or use a ListView
) and Visual States to show/hide them appropriately, but I'd prefer not to duplicate so much code.
Upvotes: 1
Views: 192
Reputation: 442
There is some kind of bug when changing the orientation.
var zoomedInStackpanel = itemGridView.ItemsPanelRoot as VirtualizingStackPanel;
zoomedInStackpanel.Orientation = Orientation.Vertical;
I gave up and used two GridViews. One for each orientation
Upvotes: 0
Reputation: 31724
Use VisualTreeHelper
to dig into the GridView's
visual tree and find the panel.
Upvotes: 1