ユーザ用ツール

サイト用ツール

サイドバー

About

Contents

Materials Link

その他

PR


wiki:windowsphone:7.1:tips:004

004 初めての Silverlight アプリケーションの作成

概要

「戻る ボタンを押した時」「回転し向きが変更された時」「アプリケーションが終了する時」に、ダイアログを表示して各メソッドが呼ばれることを確認します。

MainPage.xaml

<phone:PhoneApplicationPage 
	x:Class="BaseApp.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">
 
	<!--LayoutRoot is the root grid where all page content is placed-->
	<Grid x:Name="LayoutRoot" Background="Transparent">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
 
		<!--ContentPanel - place additional content here-->
		<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
	</Grid>
</phone:PhoneApplicationPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
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 System.Windows.Navigation;
using Microsoft.Phone.Controls;
 
namespace BaseApp
{
	// エントリーポイント
	public partial class MainPage : PhoneApplicationPage
	{
		// コンストラクタ
		public MainPage()
		{
			// コンポーネントの初期化。
			InitializeComponent();
		}
 
		// 戻るボタンが押された時に呼ばれるメソッド。
		protected override void OnBackKeyPress(CancelEventArgs e)
		{
			base.OnBackKeyPress(e);
			MessageBox.Show("OnBackKeyPress");
		}
 
		// 電話が回転し、向きが変わった時に呼ばれるメソッド。
		protected override void OnOrientationChanged(OrientationChangedEventArgs e)
		{
			base.OnOrientationChanged(e);
			MessageBox.Show("OnOrientationChanged");
		}
 
		// アプリケーション終了時に呼ばれるメソッド。
		protected override void OnRemovedFromJournal(JournalEntryRemovedEventArgs e)
		{
			base.OnRemovedFromJournal(e);
			MessageBox.Show("OnRemovedFromJournal");
		}
	}
}
Permalink wiki/windowsphone/7.1/tips/004.txt · 最終更新: 2014/11/08 01:45 (外部編集)

oeffentlich