Windows Phone 7应用程序-方向更改 [英] Windows Phone 7 applications - Orientation Change

查看:72
本文介绍了Windows Phone 7应用程序-方向更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,还有其他开发人员! 我正在使用Windows Phone 7应用程序,但我不知道对于经验丰富的应用程序来说,我认为这是一个简单的问题. 假设我有一个由两个元素组成的布局:一个ListBox(填充了很多项目)和一个TextBlock(为用户提供了一些基本说明).

Hello there fellow developers! I am working on a Windows Phone 7 app and I can't figure out what I believe is a simple problem for the more seasoned ones. Say I have a layout consisting of two elements: a ListBox (filled with an abundance of items) and a TextBlock (providing the user with some basic instructions).

当设备处于纵向"方向时,我希望它们彼此相邻;当设备的方向变为横向"时,我希望它们彼此相邻.

I want these to be one above the other when the device is in Portrait orientation and I want these to be next to each other when the device orientation changes to Landscape.

对于纵向方向,我使用的是Grid布局管理器,因为它使我可以像这样定义行的高度...行0 Height="2*",行1 Height="*"

For the Portrait orientation I am using a Grid layout manager, as it lets me define the rows' heights like so... row 0 Height="2*", row 1 Height="*"

列表框位于第0行,文本框位于第1行.现在,真正精巧的方法是将RowDefinition更改为ColumnDefinition,然后将列表框/文本块重新分配给网格的列,而不是将行分配给设备将切换到横向模式.

Listbox sits in row 0, TextBlock in row 1. Now, what would be really neat is to simple change the RowDefinitions into ColumnDefinitions and reassign the listbox/textblock to the grid's columns instead of rows for when the device switches into Landscape.

但这只是我的主意.我不知道如何优雅地完成这项工作.也许有更好的方法吗?也许这是正确的方法,并且为此目的专门构建了一些方法?

But that's just my idea. I don't know how to get this done elegantly. Maybe there's a better approach to this? Or maybe this is the correct approach and there is some method built for exactly this purpose?

谢谢您的建议!

推荐答案

默认肖像配置如何?-

<Grid>
   <Grid.RowDefinitions>
       <RowDefinition Height="2*" />
       <RowDefinition Height="*" />
   </Grid.RowDefintions>
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="2*" />
       <ColumnDefinition Width="*" />
   </Grid.ColumnDefinitions>

   <ListBox x:Name="ItemList" Grid.ColumnSpan="2" />
   <TextBlock x:Name="Instructions" Grid.Row="1" Grid.ColumnSpan="2">
      Content
   </TextBlock> 

然后在您的OrientationChanged事件中使用:-

Then in your OrientationChanged event use:-

if ((e.Orientation & PageOrientation.Portrait) == PageOrientation.Portrait)
{
     Grid.SetRow(ItemList, 0);
     Grid.SetRowSpan(ItemList, 1);
     Grid.SetColumn(ItemList, 0);
     Grid.SetColumnSpan(ItemList, 2);

     Grid.SetRow(Instructions, 1);
     Grid.SetRowSpan(Instructions, 1);
     Grid.SetColumn(Instructions, 0);
     Grid.SetColumnSpan(Instructions, 2);
}
else
{
     Grid.SetRow(ItemList, 0);
     Grid.SetRowSpan(ItemList, 2);
     Grid.SetColumn(ItemList, 0);
     Grid.SetColumnSpan(ItemList, 1);

     Grid.SetRow(Instructions, 0);
     Grid.SetRowSpan(Instructions, 2);
     Grid.SetColumn(Instructions, 1);
     Grid.SetColumnSpan(Instructions, 1);
}

这篇关于Windows Phone 7应用程序-方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆