当前位置:编程学习 > wap >>

与众不同windows phone(1)-Hello Windows Phone

介绍
与众不同 windows phone 7.5 (sdk 7.1)
• 使用 Silverlight 开发 Windows Phone 应用程序
• 使用 XNA 开发 Windows Phone 应用程序
• 使用 Silverlight 和 XNA 组合开发 Windows Phone 应用程序(在 Silverlight 中融入 XNA)


示例
1、使用 Silverlight 开发 Windows Phone App 的 Demo
MainPage.xaml
 
<phone:PhoneApplicationPage
    x:Class="Silverlight.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">

    <StackPanel>
        <!--按钮-->
        <Button Name="btn" Content="hello webabcd" />
    </StackPanel>
 
</phone:PhoneApplicationPage>
 
MainPage.xaml.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace Silverlight
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // 弹出 MessageBox 信息
            btn.Click += delegate { MessageBox.Show("hello webabcd"); };
        }
    }
}
 


2、使用 XNA 开发 Windows Phone App 的 Demo
Game1.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace XNA
{
    // 启动时先 Initialize,再 LoadContent,退出时 UnloadContent
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        // 图形设备(显卡)管理器,XNA 在游戏窗口上做的所有事情都要通过此对象
        GraphicsDeviceManager graphics;

        // 精灵绘制器
        SpriteBatch spriteBatch;

        // 2D 纹理对象
        Texture2D sprite;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            // 指定游戏窗口的宽和高,不设置的话会花屏
            graphics.PreferredBackBufferWidth = this.Window.ClientBounds.Width;
            graphics.PreferredBackBufferHeight = this.Window.ClientBounds.Height;

            Content.RootDirectory = "Content";

            // 两次绘制的间隔时间,本例为每 1/30 秒绘制一次,即帧率为 30 fps。此属性默认值为 60 fps
            TargetElapsedTime = TimeSpan.FromSeconds(1f / 30);

            // 当禁止在锁屏状态下运行应用程序空闲检测(默认是开启的)时,将此属性设置为 1 秒钟,可减少锁屏启动应用程序时的耗电量。此属性默认值为 0.02 秒
            InactiveSleepTime = TimeSpan.FromSeconds(1);
        }

        /// <summary>
        /// 游戏运行前的一些初始化工作
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
        }

        /// <summary>
        /// 加载游戏所需用到的资源,如图像和音效等
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // 将图片 Image/Son 加载到 Texture2D 对象中
            sprite = Content.Load<Texture2D>("Image/Son");
        }

        /// <summary>
        /// 手工释放对象,游戏退出时会自动调用此方法
        /// 注:XNA 会自动进行垃圾回收
        /// </summary>
        protected override void UnloadContent()
        {

        }

        /// <summary>
     

补充:移动开发 , Windows Phone ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,