zoukankan      html  css  js  c++  java
  • PROGRAMMING_WINDOWS_PHONE_7 读书笔记—基础篇(横向和纵向视图)

    作品目标: Windows Phone 7开发技术实用手册。

    Programming_Windows_Phone_7 读书笔记规划

    • 基础篇
      基础篇是Silvelight和XNA共有的部分,分为
      • 横向和纵向视图
      • 触控
      • Sensors和服务(加速器、Bing Map、云计算)
      • 全球化
      • 应用设计问题集锦
    • Silverlight篇
      结合《Programming_Windows_Phone_7》与Windows Phone Silverlight动手实验程序,分为
      • 元素和属性
      • 复杂的布局
      • 应用程序菜单栏
      • 数据绑定和项的控制
      • 动画和多媒体
      • 数据透视和全景
    • XNA篇
      结合《Programming_Windows_Phone_7》与Windows Phone XNA框架动手实验程序。
      • 运动的规则
      • 2D游戏中实现触摸和手势
      • 2D游戏中实现消息发送和墓碑机制
      • 3D游戏的触控和基本3D物理学
    参考资料:
    读书笔记的内容源于也多于Programming_Windows_Phone_7,是Windows Phone 7开发技术学习的合集。目标是写成Windows Phone开发技术实用手册。
    规划的章节若有不合理之处,日后将修改。
    虽然大部分内容看起来都似曾相识,也许别人都写过。在整理时,力求从深度和不同的侧面诠释Windows Phone的开发技术。由于个人能力和水平有待提高,很多问题的分析还很肤浅。敬请各位不吝赐教,提出改进建议。
     
     

    Silverlight 实现自动横向和纵向视图显示

    本例中使用phone:WebBrowser实现浏览网页,当我们旋转模拟器时,发现网页并没有随着模拟器旋转,即网页没有自动横向显示。其实纵向和横向自动调整显示非常容易。
    打开MainPage.xaml,中调整 PhoneApplicationPage中属性SupportedOrientations的设定。
    <phone:PhoneApplicationPage
    x:Class="MiniBrowser.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
     
     
    修改方法:
    SupportedOrientations="Portrait"
     
     
     
     
    to:
    SupportedOrientations="PortraitOrLandscape"
     
     
     
     

    SupportedOrientations

    Gets or sets the supported phone orientations.
    SupportedOrientations PhoneApplicationPage的属性. SupportedPageOrientation可以设置Portrait(纵向), Landscape(横向)PortraitOrLandscape(自动纵向或者横向)

    WebBrowser属性

    MainPage.xaml中
    <phone:WebBrowser HorizontalAlignment="Stretch" Name="webBrowser1" VerticalAlignment="Stretch" Height="Auto" Width="Auto" Source="http://cn.bing.com"/>
     

    Name

    Gets or sets the identifying name of the object. When a XAML processor creates the object tree from XAML markup, run-time code can refer to the XAML-declared object by this name.

    Property Value

    Type: System.String
    The name of the object, which must be a string that is valid in the XamlName Grammar. The default is an empty string.

    Remarks

    The following is the normative grammar for a string that is used as a name or key in Silverlight.
    XamlName ::= NameStartChar (NameChar)*
    NameStartChar ::= LetterCharacter | '_'
    NameChar ::= NameStartChar | DecimalDigit
    LetterCharacter ::= ('a'-'z') | ('A'–'Z')
    DecimalDigit ::= '0'-'9'
    CombiningCharacter::= none
    Characters are restricted to the lower ASCII range, and more specifically to Roman alphabet uppercase and lowercase letters, digits, and the underscore (_) character.
    The Unicode character range is not supported.
    A name cannot begin with a digit. Some tool implementations prepend an underscore (_) to a string if the user supplies a digit as the initial character.
     

    Source

    Gets or sets the URI location of the WebBrowser control.
    此属性可以为空,也可以指定URI地址。

    HorizontalAlignment

    Gets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control.
    Member name
    Description
    Left
    An element aligned to the left of the layout slot for the parent element.
    Center
    An element aligned to the center of the layout slot for the parent element.
    Right
    An element aligned to the right of the layout slot for the parent element.
    Stretch
    An element stretched to fill the entire layout slot of the parent element.

    Orientation Events

    PhoneApplicationPage.OnOrientationChanged Method
    This method is called after the Orientation property has been changed.
    Namespace:  Microsoft.Phone.Controls
    Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)
    Occurs after the phone is rotated or the SupportedOrientations property has changed.
    在MainPage.xaml.cs中重载OnOrientationChanged方法,实现特殊的控制。
    using System.Windows.Controls;
    using Microsoft.Phone.Controls;
     
    namespace SilverlightOrientationDisplay
    {
    public partial class MainPage : PhoneApplicationPage
    {
    public MainPage()
    {
    InitializeComponent();
    txtblk.Text = Orientation.ToString();
    }
     
    protected override void OnOrientationChanged(OrientationChangedEventArgs args)
    {
    txtblk.Text = args.Orientation.ToString();
    base.OnOrientationChanged(args);
    }
    }
    }
    MainPage.xaml.cs文件中的txtblk定义在MainPage.xaml文件中的TextBlockName属性。MainPage.xaml中定义TextBlcok的代码如下:
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <TextBlock Name="txtblk"
    HorizontalAlignment="Center"
    VerticalAlignment="Center" />
    </Grid>
     
     

    XNA横向和纵向视图显示

    默认情况下,XNA for Windows Phone的后台缓冲区大小为800*480,在构造Game类中,可以设置缓冲区的大小,设置方法如下:
    graphics.PreferredBackBufferWidth = 320;
    graphics.PreferredBackBufferHeight = 480;
    全屏显示模式设置方法:
    graphics.IsFullScreen = true;
     
    设置范围:
    纵向模式 240 × 240 ~ 480 × 800
    横向模式 800 × 480
    public class Game1 : Microsoft.Xna.Framework.Game
    {
    GraphicsDeviceManager graphics;
     
    public Game1()
    {
    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
     
    // Allow portrait mode as well
    graphics.SupportedOrientations = DisplayOrientation.Portrait |
    DisplayOrientation.LandscapeLeft |
    DisplayOrientation.LandscapeRight;
     
    // Frame rate is 30 fps by default for Windows Phone.
    TargetElapsedTime = TimeSpan.FromTicks(333333);
    }
    }
     

    DisplayOrientation Enumeration

    Defines the display orientation
    Members
    Member name
    Description
    Default
    默认方向
    LandscapeLeft
    逆时针方向旋转90度横向显示(宽度大于高度)
    LandscapeRight
    顺时针方向旋转90度横向显示(宽度大于高度)
    Portrait
    纵向显示(高度大于宽度)
     

    Game.TargetElapsedTime Property

    Gets or sets the target time between calls to Update when IsFixedTimeStep is true.
    Remarks
    When the game framerate is less than TargetElapsedTime, IsRunningSlowly will return true.
    The default value for TargetElapsedTime is 1/60th of a second.
    A fixed-step Game tries to call its Update method on the fixed interval specified in TargetElapsedTime. Setting Game.IsFixedTimeStep to true causes a Game to use a fixed-step game loop. A new XNA project uses a fixed-step game loop with a default TargetElapsedTime of 1/60th of a second.
    In a fixed-step game loop, Game calls Update once the TargetElapsedTime has elapsed. After Update is called, if it is not time to call Update again, Game calls Draw. After Draw is called, if it is not time to call Update again, Game idles until it is time to call Update.
    If Update takes too long to process, Game sets IsRunningSlowly totrue and calls Update again, without calling Draw in between. When an update runs longer than the TargetElapsedTime, Game responds by calling Update extra times and dropping the frames associated with those updates to catch up. This ensures that Update will have been called the expected number of times when the game loop catches up from a slowdown. You can check the value of IsRunningSlowly in your Update if you want to detect dropped frames and shorten your Update processing to compensate. You can reset the elapsed times by calling ResetElapsedTime.
    When your game pauses in the debugger, Game will not make extra calls to Update when the game resumes.

    TimeSpan.FromTicks Method

    Returns a TimeSpan that represents a specified time, where the specification is in units of ticks.
    Namespace:  System
    Assembly:  mscorlib (in mscorlib.dll)
    public static TimeSpan FromTicks(
        long value
    )

    Game.TargetElapsedTime Property

    Gets or sets the target time between calls to Update when IsFixedTimeStep is true.
    Syntax
    public TimeSpan TargetElapsedTime { get; set; }
    Property Value
    The target time period for the game loop.
    Exceptions
    Exception type
    Condition
    The value specified for TargetElapsedTime is not greater than zero. Specify a nonzero positive value.
    Remarks
    When the game framerate is less than TargetElapsedTime, IsRunningSlowly will return true.
    The default value for TargetElapsedTime is 1/60th of a second.
    A fixed-step Game tries to call its Update method on the fixed interval specified in TargetElapsedTime. Setting Game.IsFixedTimeStep to true causes a Game to use a fixed-step game loop. A new XNA project uses a fixed-step game loop with a default TargetElapsedTime of 1/60th of a second.
    In a fixed-step game loop, Game calls Update once the TargetElapsedTime has elapsed. After Update is called, if it is not time to call Update again, Game calls Draw. After Draw is called, if it is not time to call Update again, Game idles until it is time to call Update.
    If Update takes too long to process, Game sets IsRunningSlowly totrue and calls Update again, without calling Draw in between. When an update runs longer than the TargetElapsedTime, Game responds by calling Update extra times and dropping the frames associated with those updates to catch up. This ensures that Update will have been called the expected number of times when the game loop catches up from a slowdown. You can check the value of IsRunningSlowly in your Update if you want to detect dropped frames and shorten your Update processing to compensate. You can reset the elapsed times by calling ResetElapsedTime.
    When your game pauses in the debugger, Game will not make extra calls to Update when the game resumes.
     

    作者:雪松
    出处:http://www.cnblogs.com/xuesong/
    本文版权归作者和博客园共有,欢迎转载,转载请标明作者、出处和原文链接。
    未经作者同意请您务必保留此声明。
  • 相关阅读:
    CF div2 325 C
    CF div2 325 B
    CF div2 325 A
    CF div2 322 C
    CF div2 322 B
    CF div2 322 A
    Sudoku Solver POJ 2676 LightOJ 1397
    逆序数(归并排序 )
    RMQ算法
    Socket编程:listen()函数英文翻译
  • 原文地址:https://www.cnblogs.com/xuesong/p/1908084.html
Copyright © 2011-2022 走看看