Windows Phone 7 布局与大小

简介:

 

 

1、整体的布局

 


 
 
  1. 代码  
  2.  
  3. <phone:PhoneApplicationPage   
  4.     x:Class="SilverlightCornersAndEdges.MainPage" 
  5.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  6.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  7.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  8.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  9.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  10.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  11.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  12.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  13.     Foreground="{StaticResource PhoneForegroundBrush}" 
  14.     SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" 
  15.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  16.     shell:SystemTray.IsVisible="True"> 
  17.  
  18.     <!--LayoutRoot contains the root grid where all other page content is placed--> 
  19.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  20.         <Grid.RowDefinitions> 
  21.             <RowDefinition Height="Auto"/> 
  22.             <RowDefinition Height="*"/> 
  23.         </Grid.RowDefinitions> 
  24.  
  25.         <!--TitlePanel contains the name of the application and page title--> 
  26.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
  27.             <TextBlock x:Name="ApplicationTitle" Text="CORNERS AND EDGES" Style="{StaticResource PhoneTextNormalStyle}"/> 
  28.             <TextBlock x:Name="PageTitle" Text="main page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
  29.         </StackPanel> 
  30.  
  31.         <!--ContentPanel - place additional content here--> 
  32.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
  33.             <TextBlock Text="Top-Left" 
  34.                        VerticalAlignment="Top" 
  35.                        HorizontalAlignment="Left" /> 
  36.  
  37.             <TextBlock Text="Top-Center" 
  38.                        VerticalAlignment="Top" 
  39.                        HorizontalAlignment="Center" /> 
  40.  
  41.             <TextBlock Text="Top-Right" 
  42.                        VerticalAlignment="Top" 
  43.                        HorizontalAlignment="Right" /> 
  44.  
  45.             <TextBlock Text="Center-Left" 
  46.                        VerticalAlignment="Center" 
  47.                        HorizontalAlignment="Left" /> 
  48.  
  49.             <TextBlock Text="Center" 
  50.                        VerticalAlignment="Center" 
  51.                        HorizontalAlignment="Center" /> 
  52.  
  53.             <TextBlock Text="Center-Right" 
  54.                        VerticalAlignment="Center" 
  55.                        HorizontalAlignment="Right" /> 
  56.  
  57.             <TextBlock Text="Bottom-Left" 
  58.                        VerticalAlignment="Bottom" 
  59.                        HorizontalAlignment="Left" /> 
  60.  
  61.             <TextBlock Text="Bottom-Center" 
  62.                        VerticalAlignment="Bottom" 
  63.                        HorizontalAlignment="Center"  /> 
  64.  
  65.             <TextBlock Text="Bottom-Right" 
  66.                        VerticalAlignment="Bottom" 
  67.                        HorizontalAlignment="Right" /> 
  68.         </Grid> 
  69.     </Grid> 
  70.       
  71.     <!-- Sample code showing usage of ApplicationBar  
  72.     <phone:PhoneApplicationPage.ApplicationBar> 
  73.         <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> 
  74.             <shell:ApplicationBarIconButton x:Name="appbar_button1" IconUri="/Images/appbar_button1.png" Text="Button 1"></shell:ApplicationBarIconButton> 
  75.             <shell:ApplicationBarIconButton x:Name="appbar_button2" IconUri="/Images/appbar_button2.png" Text="Button 2"></shell:ApplicationBarIconButton> 
  76.             <shell:ApplicationBar.MenuItems> 
  77.                 <shell:ApplicationBarMenuItem x:Name="menuItem1" Text="MenuItem 1"></shell:ApplicationBarMenuItem> 
  78.                 <shell:ApplicationBarMenuItem x:Name="menuItem2" Text="MenuItem 2"></shell:ApplicationBarMenuItem> 
  79.             </shell:ApplicationBar.MenuItems> 
  80.         </shell:ApplicationBar> 
  81.     </phone:PhoneApplicationPage.ApplicationBar> 
  82.     --> 
  83.  
  84.  
  85. </phone:PhoneApplicationPage> 

HorizontalAlignment 水平布局属性

HorizontalAlignment 垂直布局属性

Margin 边缘布局属性

Padding 填充属性

2、大小的设定

 

 

xaml

 


 
 
  1. 代码  
  2.  
  3. <phone:PhoneApplicationPage   
  4.     x:Class="SilverlightWhatSize.MainPage" 
  5.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  6.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  7.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  8.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  9.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  10.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  11.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  12.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  13.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  14.     Foreground="{StaticResource PhoneForegroundBrush}" 
  15.     SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" 
  16.     shell:SystemTray.IsVisible="True"> 
  17.  
  18.     <!--LayoutRoot is the root grid where all page content is placed--> 
  19.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  20.         <Grid.RowDefinitions> 
  21.             <RowDefinition Height="Auto"/> 
  22.             <RowDefinition Height="*"/> 
  23.         </Grid.RowDefinitions> 
  24.  
  25.         <!--TitlePanel contains the name of the application and page title--> 
  26.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
  27.             <TextBlock x:Name="ApplicationTitle" Text="SILVERLIGHT WHAT SIZE" Style="{StaticResource PhoneTextNormalStyle}"/> 
  28.             <TextBlock x:Name="PageTitle" Text="main page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
  29.         </StackPanel> 
  30.  
  31.         <!--ContentPanel - place additional content here--> 
  32.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" 
  33.               SizeChanged="ContentPanel_SizeChanged"> 
  34.             <TextBlock Name="txtblk" 
  35.                        HorizontalAlignment="Center" 
  36.                        VerticalAlignment="Center" /> 
  37.         </Grid> 
  38.     </Grid> 
  39.    
  40.     <!--Sample code showing usage of ApplicationBar--> 
  41.     <!--<phone:PhoneApplicationPage.ApplicationBar> 
  42.         <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> 
  43.             <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/> 
  44.             <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/> 
  45.             <shell:ApplicationBar.MenuItems> 
  46.                 <shell:ApplicationBarMenuItem Text="MenuItem 1"/> 
  47.                 <shell:ApplicationBarMenuItem Text="MenuItem 2"/> 
  48.             </shell:ApplicationBar.MenuItems> 
  49.         </shell:ApplicationBar> 
  50.     </phone:PhoneApplicationPage.ApplicationBar>--> 
  51.  
  52. </phone:PhoneApplicationPage> 

cs

 


 
 
  1. 代码  
  2.  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.Linq;  
  6. using System.Net;  
  7. using System.Windows;  
  8. using System.Windows.Controls;  
  9. using System.Windows.Documents;  
  10. using System.Windows.Input;  
  11. using System.Windows.Media;  
  12. using System.Windows.Media.Animation;  
  13. using System.Windows.Shapes;  
  14. using Microsoft.Phone.Controls;  
  15.  
  16. namespace SilverlightWhatSize  
  17. {  
  18.     public partial class MainPage : PhoneApplicationPage  
  19.     {  
  20.         // Constructor  
  21.         public MainPage()  
  22.         {  
  23.             InitializeComponent();  
  24.         }  
  25.  
  26.         private void ContentPanel_SizeChanged(object sender, SizeChangedEventArgs e)  
  27.         {  
  28.             txtblk.Text = String.Format("ContentPanel size: {0}\n" +  
  29.                                         "TitlePanel size: {1}\n" +  
  30.                                         "LayoutRoot size: {2}\n" +  
  31.                                         "MainPage size: {3}\n" +  
  32.                                         "Frame size: {4}",  
  33.                                         e.NewSize,  
  34.                                         new Size(TitlePanel.ActualWidth, TitlePanel.ActualHeight),  
  35.                                         new Size(LayoutRoot.ActualWidth, LayoutRoot.ActualHeight),  
  36.                                         new Size(this.ActualWidth, this.ActualHeight),  
  37.                                         Application.Current.RootVisual.RenderSize);  
  38.  
  39.         }  
  40.     }  

 

本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1079250



相关文章
|
Windows
构建布局良好的Windows程序
构建布局良好的Windows程序
|
Android开发 iOS开发 Windows
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
不久前,随着最后一家WP手机厂商惠普宣布取消今后Windows Phone的研发计划,以及微软官方声明对WP8.1系统今后所有升级维护的终止,WP手机,作为曾经和安卓手机、苹果手机并驾齐驱的三大智能手机之一,正式寿终正寝。
1802 0
Windows Phone 寿终正寝了,这些经典机型你还记得吗?
|
XML 开发框架 前端开发
Windows Phone快速入门需掌握哪些能力
在此之前,先普及下Windows Phone的概念和开发工具的介绍。 Windows Phone是微软公司开发的手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验集成至手机中。2012年6月21日,微软正式发布Windows Phone 8,采用和Windows 8相同的Windows NT内核,同时也针对市场的Windows Phone 7.5发布Windows Phone 7.8。
305 0
Windows Phone快速入门需掌握哪些能力
|
移动开发 Android开发 开发者
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
在Build 2014大会上,微软正式发布了传闻已久的Windows Phone 8.1系统,所有的Windows Phone 8手机都可以升级,微软这次可谓是十分厚道。虽然并非迭代升级,但WP 8.1还是拥有很多重大更新,对于微软进一步完善移动平台拥有积极的意义。下面,就一起来了解一下WP 8.1的主要新特性。
350 0
Windows Phone 8.1 新功能汇总 开发者预览版开放下载
|
编解码 前端开发 JavaScript
Windows Phone 下开发 LBS 应用
基于位置的服务(Location Based Service,LBS),它是通过电信移动运营商的无线电通讯网络(如GSM网、CDMA网)或外部定位方式(如GPS)获取移动终端用户的位置信息(地理坐标,或大地坐标),在GIS(Geographic Information System,地理信息系统)平台的支持下,为用户提供相应服务的一种增值业务。
352 0
|
Windows 缓存 异构计算
背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIElement 的位置, UIElement 的布局, UIElement 的其他特性
原文:背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIElement 的位置, UIElement 的布局, UIElement 的其他特性 [源码下载] 背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIE...
1111 0