Alessandro Del Sole's Blog

/* A programming space about Microsoft® .NET® */
posts - 159, comments - 0, trackbacks - 0

My Links

News

Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2015!

Pre-order VB 2015 Unleashed Pre-order my new book "Visual Basic 2015 Unleashed". Click for more info!

My new book on LightSwitch!

Visual Studio LightSwitch Unleashed My book "Visual Studio LightSwitch Unleashed" is available. Click the cover!

Your visits

Follow me on Twitter!

CodePlex download Download my open-source projects from CodePlex!

Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

WinRT: ho to solve if ListView and GridView lose their way

In a Windows Store App I've been working on, I had to face a particular problem. It is a problem that can randomly occur with the GridView and ListView controls and it probably depends on the DataTemplate you use.

Consider the following GridView:

                <GridView Name="MyView" ItemsSource="{Binding}" Margin="0,15,0,0" HorizontalAlignment="Left">
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <!-- custom DataTemplate -->
                        </DataTemplate>
                    </GridView.ItemTemplate>
                </GridView>

In this page I have this object; then I navigate to a secondary page. From the secondary page, I navigate back to the page where I have the GridView.

As a result, instead of showing items horizontally (as required), the control shows them vertically losing the original orientation.

I searched on the Internet but the only one taling about this problem is a guy at Microsoft, who provides a possible solution in this blog post. Unfortunately that solution did not work for me, so what I did is changing the template of the panel for the view. In this case I used a StackPanel. This works well for me because I have a few items and I don't need virtualization. In code:

                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>

In this way, everything worked correctly. In conclusion, if you face this problem remember to work on the ItemsPanelTemplate.

Alessandro

Print | posted on giovedì 14 marzo 2013 11:14 | Filed Under [ Windows 8 & WinRT ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 1 and 2 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET