简体   繁体   中英

Create a full screen GridView in XAML

I want to create a full screen GridView control for a Metro Style application in Windows 8 that grows and adapts to the user changing their screen resolution.

I'm trying to imitate the calendar application on Windows 8, wen you swap the metro screen between monitors, the size of each square (date) changes so that the screen is always filled.

Typically you would have a fluid ItemTemplate I need to ensure that the whole screen is full, so sometimes the GridView items will be small (when running on a tablet) and sometimes they will be large (when running on my Desktop).

Can I achieve this using XAML or do I have to get funky with changing the ItemTemplate for the GridView when the screen size changes?

The control in other xaml frameworks that does what you want is called UniformGrid. It let you specify the number of Rows or Columns and then sized each child item to the appropriate size.

UniformGrid currently doesn't appear in the WinRT xaml stack, but it's not difficult to port (I have done it once but don't have access to the source). You can get the source for the Silverlight version from Jeff Wilcox - Uniform Grid .

For a calendar style app you'll have a uniform grid for the rows and then each row will have one for the columns..

I think you should be able to place the GridView in a Grid, and that should take care of flexible layout. As long as the Grid is the root element of the page that you assign to Windows.UI.Xaml.Window.Current property, and the GridView is the only child of the Grid, it should stretch horizontally and vertically to fill the screen.

To get a Calendar-type look, you can put the GridView in the second row of the Grid, and have the title etc on the first row.

也许您可以使用Viewbox控件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM