成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Windows Phone開發(6):處理屏幕方向的改變

移動開發
前面我們討論過,Silverlight for Windows Phone的頁面布局有三個常用的布局控件,那么,當屏幕方向改變后,我們所做的對布局的更改基礎上是基于這幾個容器進行的操作。本文我將通過三個示例來分別說明。

俺們都知道,智能手機可以通過旋轉手機來改變屏幕的顯示方向,更多的時候,對于屏幕方向的改變,我們要做出相應的處理,例如,當手機屏幕方向從縱向變為橫向時,可能要重新排列頁面上的控件以適應顯示區域的變化。

 
前面我們討論過,Silverlight for Windows Phone的頁面布局有三個常用的布局控件,那么,當屏幕方向改變后,我們所做的對布局的更改基礎上是基于這幾個容器進行的操作。
 
本文我將通過三個示例來分別說明。
開始之前,先說一下PhoneApplicationPage類的 OrientationChanged事件,該事件就是當屏幕的方向改變之后發生,我們從事件參數 OrientationChangedEventArgs類的實例的Orientation屬性中獲取當前屏幕的方向,即改變后的方向,比如,原來屏幕是 縱向,現在我把手機屏幕改為橫向,則Orientation屬性獲取到的方向就是橫向的,呵呵,當然也包括從哪個方向旋轉過來的,這里只是舉例而已。
 

要使頁面支持旋轉,要把PhoneApplicationPage的SupportedOrientations屬性改為PortraitOrLandscape,然后可以通過定義OrientationChanged事件來處理布局。形如:

  1. <phone:PhoneApplicationPage  
  2.     .............. 
  3.     SupportedOrientations="PortraitOrLandscape"  
  4.     Orientation="Portrait" 
  5.     OrientationChanged="PhoneApplicationPage_OrientationChanged"

一、Grid控件的處理。

  1. <phone:PhoneApplicationPage  
  2.     x:Class="Sample_PageDir.Page1" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  10.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  11.     Foreground="{StaticResource PhoneForegroundBrush}" 
  12.     mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" 
  13.     shell:SystemTray.IsVisible="True" 
  14.     SupportedOrientations="PortraitOrLandscape"  
  15.     Orientation="Portrait" 
  16.     OrientationChanged="PhoneApplicationPage_OrientationChanged"
  17.  
  18.     <Grid x:Name="layoutRoot"
  19.         <Grid.RowDefinitions> 
  20.             <RowDefinition Height="Auto" /> 
  21.             <RowDefinition Height="Auto" /> 
  22.         </Grid.RowDefinitions> 
  23.         <Grid.ColumnDefinitions> 
  24.             <ColumnDefinition Width="Auto" /> 
  25.             <ColumnDefinition Width="Auto" /> 
  26.         </Grid.ColumnDefinitions> 
  27.         <Image x:Name="img" Source="http://gubapic.eastmoney.com/member/e68/e681999/e68199920091216131540.jpg" Stretch="UniformToFill" Width="270" Grid.Row="0" Grid.Column="0" /> 
  28.         <TextBlock x:Name="txtBlock" 
  29.             Grid.Row="1" 
  30.             Grid.Column="0" 
  31.             FontSize="70" 
  32.             Margin="28"
  33.             <Run Foreground="Coral">信春哥</Run> 
  34.             <LineBreak/> 
  35.             <Run Foreground="Yellow">唱情歌</Run> 
  36.             <LineBreak/> 
  37.             <Run Foreground="SkyBlue">不掛科</Run> 
  38.         </TextBlock> 
  39.     </Grid> 
  40. </phone:PhoneApplicationPage> 

頁面主要有兩個控件,一個用于顯示圖片,一個用于顯示文本信息,通過事件處理代碼來相應改變兩個控件的布局。

  1. private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) 
  2.     // 如果是橫向的 
  3.     if (e.Orientation == PageOrientation.Landscape || 
  4.         e.Orientation == PageOrientation.LandscapeLeft || 
  5.         e.Orientation == PageOrientation.LandscapeRight) 
  6.     { 
  7.         Grid.SetColumn(this.img, 0); 
  8.         Grid.SetRow(this.img, 0); 
  9.         Grid.SetRow(this.txtBlock, 0); 
  10.         Grid.SetColumn(this.txtBlock, 1); 
  11.     } 
  12.     // 如果是縱向 
  13.     else if (e.Orientation == PageOrientation.Portrait || 
  14.         e.Orientation == PageOrientation.PortraitDown || 
  15.         e.Orientation == PageOrientation.PortraitUp) 
  16.     { 
  17.         Grid.SetColumn(this.img, 0); 
  18.         Grid.SetRow(this.img, 0); 
  19.         Grid.SetRow(this.txtBlock, 1); 
  20.         Grid.SetColumn(this.txtBlock, 0); 
  21.     } 
  22.     else 
  23.     { 
  24.         Grid.SetColumn(this.img, 0); 
  25.         Grid.SetRow(this.img, 0); 
  26.         Grid.SetRow(this.txtBlock, 1); 
  27.         Grid.SetColumn(this.txtBlock, 0); 
  28.     } 

按F5運行程序,默認的屏幕方向是縱向的,如下圖所示:

好,現在,我們把屏幕旋轉一下,看看會怎么樣。

別走開,下頁更精彩

#p#

二、StackPanel控件的處理。

  1. <phone:PhoneApplicationPage  
  2.     x:Class="Sample_PageDir.Page2" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  10.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  11.     Foreground="{StaticResource PhoneForegroundBrush}" 
  12.     SupportedOrientations="PortraitOrLandscape" 
  13.     OrientationChanged="PhoneApplicationPage_OrientationChanged" 
  14.     Orientation="Portrait" 
  15.     mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" 
  16.     shell:SystemTray.IsVisible="True"
  17.     <phone:PhoneApplicationPage.Resources> 
  18.         <Style TargetType="TextBlock"
  19.             <Setter Property="FontSize" Value="46"/> 
  20.         </Style> 
  21.     </phone:PhoneApplicationPage.Resources> 
  22.     <StackPanel x:Name="pl"
  23.         <TextBlock Text="文本一"/> 
  24.         <TextBlock Text="文本二"/> 
  25.         <TextBlock Text="文本三"/> 
  26.     </StackPanel> 
  27. </phone:PhoneApplicationPage> 

后臺事件處理代碼。

  1. private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) 
  2.     if (e.Orientation == PageOrientation.Landscape || 
  3.         e.Orientation == PageOrientation.LandscapeLeft || 
  4.         e.Orientation == PageOrientation.LandscapeRight) 
  5.     { 
  6.         this.pl.Orientation = System.Windows.Controls.Orientation.Horizontal; 
  7.     } 
  8.     else 
  9.     { 
  10.         this.pl.Orientation = System.Windows.Controls.Orientation.Vertical; 
  11.     } 

運行,默認方向是縱向。

把屏幕旋轉后。

三、Canvas控件的處理。

  1. <phone:PhoneApplicationPage  
  2.     x:Class="Sample_PageDir.Page3" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  10.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  11.     Foreground="{StaticResource PhoneForegroundBrush}" 
  12.     SupportedOrientations="PortraitOrLandscape" 
  13.     Orientation="Portrait" 
  14.     OrientationChanged="PhoneApplicationPage_OrientationChanged" 
  15.     mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" 
  16.     shell:SystemTray.IsVisible="True"
  17.     <Canvas x:Name="cv"
  18.         <Rectangle x:Name="rect1" 
  19.             Width="232" 
  20.             Height="238" 
  21.             Fill="Red" 
  22.             Canvas.Left="88" 
  23.             Canvas.Top="88"/> 
  24.         <Rectangle x:Name="rect2" 
  25.             Height="192" 
  26.             Width="275" 
  27.             Fill="Yellow" 
  28.             Canvas.Top="268" 
  29.             Canvas.Left="155"/> 
  30.     </Canvas> 
  31. </phone:PhoneApplicationPage> 

后臺代碼。后臺代碼。

  1. private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) 
  2.     if (e.Orientation== PageOrientation.Landscape||e.Orientation== PageOrientation.LandscapeLeft||e.Orientation== PageOrientation.LandscapeRight) 
  3.     { 
  4.         Canvas.SetTop(this.rect1, 37); 
  5.         Canvas.SetLeft(this.rect1, 46); 
  6.         Canvas.SetTop(this.rect2, 240); 
  7.         Canvas.SetLeft(this.rect2, 462); 
  8.     } 
  9.     else 
  10.     { 
  11.         Canvas.SetTop(this.rect1, 88); 
  12.         Canvas.SetLeft(this.rect1, 88); 
  13.         Canvas.SetTop(this.rect2, 268); 
  14.         Canvas.SetLeft(this.rect2, 155); 
  15.     } 

看看效果。看看效果。

縱向。

橫向。

責任編輯:閆佳明 來源: oschina
相關推薦

2012-06-12 10:43:20

Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-16 17:02:50

Windows Pho概論

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2010-04-08 17:40:23

Windows Pho

2010-07-16 15:29:02

Windows Pho

2012-08-16 10:35:50

Windows Pho

2011-06-07 11:35:38

Windows Pho

2013-04-17 13:27:04

Windows PhoWindows Pho

2013-07-31 13:03:51

Windows PhoWindows Pho

2013-04-17 14:47:19

Windows PhoWindows Pho

2013-04-19 16:52:24

Windows PhoWindows Pho

2013-07-31 12:50:39

搭建Windows PWindows Pho

2013-07-31 13:13:50

Windows PhoMVVM模式

2010-12-14 18:48:49

微軟

2012-06-04 14:47:58

Windows Pho
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产激情视频 | 国产欧美精品一区二区 | 色偷偷人人澡人人爽人人模 | 91精品久久久久久久久 | 午夜网| 国产成人精品一区二区三区在线 | 色呦呦在线| 精品欧美在线观看 | 免费观看黄网站 | 99re视频在线免费观看 | 欧美黄视频 | 91网站在线观看视频 | 成人免费视频播放 | 亚洲精品日韩一区二区电影 | 久久久精 | 国产精品久久久久久一区二区三区 | 国产精品久久 | 欧美成人一区二区 | 国产yw851.c免费观看网站 | 91在线精品秘密一区二区 | 一区二区三区在线免费观看 | a在线免费观看视频 | 少妇精品久久久久久久久久 | 亚洲巨乳自拍在线视频 | 在线日韩福利 | 拍真实国产伦偷精品 | 欧美日韩亚洲成人 | 欧美一级淫片免费视频黄 | 欧美精品成人一区二区三区四区 | 在线不卡视频 | 日韩在线播放一区 | 欧美日韩综合精品 | 亚洲第1页| 欧美成人a∨高清免费观看 老司机午夜性大片 | 国内av在线| 97免费在线观看视频 | aa级毛片毛片免费观看久 | 国产精品久久久久久久久久久久 | 91视频网 | 日韩精品免费视频 | 成人久久久 |