OneDrive へ移動MainPage メイン画面の背景に大きなイラストを設定しました。ファイルは、『Assets フォルダ』に保存して参照しています
NextPage 次画面は、LinearGradientBrush でグラデーションにしました。
App.xaml.cs ページの設定は、Microsoft のテンプレートを無視しました。本来の WPF と同じような形でフレーム内のコンテンツを複数ページで切り替える形にしています。
using System;
using System.Diagnostics;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Simple_Pages {
// *************************************************
// クラス
// *************************************************
sealed partial class App : Application {
public static Frame rootFrame = null;
public static MainPage mainPage;
public static NextPage nextPage;
// *************************************************
// コンストラクタ
// *************************************************
public App() {
this.InitializeComponent();
this.Suspending += OnSuspending;
}
// *************************************************
// アプリケーションがエンド ユーザーによって正常に起動された
// *************************************************
protected override void OnLaunched(LaunchActivatedEventArgs args) {
// ***********************************************
// Window => Current => Content
// Content( Frame => Content(MainPage) )
// ***********************************************
// 初回は Windows 内に置く フレームを作成
if (rootFrame == null) {
rootFrame = new Frame();
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null) {
// メインページの初回ロード
rootFrame.Content = new MainPage();
// 次ページを最初に作成しておく
nextPage = new NextPage();
}
// 現在のウィンドウをアクティブにします
Window.Current.Activate();
}
// *************************************************
// アプリケーションの実行が中断されたときに呼び出されます
// *************************************************
private void OnSuspending(object sender, SuspendingEventArgs e) {
Debug.WriteLine("アプリケーションの実行が中断されました");
var deferral = e.SuspendingOperation.GetDeferral();
// アプリケーションの状態を保存してバックグラウンドの動作があれば停止します
deferral.Complete();
}
}
}
MainPage.xaml MainPage と NextPage を用意していますが、NextPage は、MainPage をコピーしてリネームしたものです。
<Page x:Class="Simple_Pages.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Simple_Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Loaded="Page_Loaded"> <!--画面定義--> <Grid> <Grid.Background> <ImageBrush ImageSource="Assets/1378650512243910.jpeg" Stretch="None" /> </Grid.Background> <Button Content="次ページ" HorizontalAlignment="Left" Height="41" Margin="34,30,0,0" VerticalAlignment="Top" Width="136" Click="Button_Click_1" /> </Grid> </Page>
MainPage.xaml.cs ページの切り替えは、Navigate メソッドを使わずに直接ページのインスタンスをセットしています。そうする為に、App クラスに参照用に static な変数を作成して、インスタンスを保存しています。App.rootFrame.Content = App.nextPage;※ よって、Page.OnNavigatedTo イベントは発生しません
using System;
using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Simple_Pages {
// *************************************************
// クラス
// *************************************************
public sealed partial class MainPage : Page {
// *************************************************
// コンストラクタ
// *************************************************
public MainPage() {
this.InitializeComponent();
App.mainPage = this;
}
// *************************************************
// ページが Frame にロードされた時に実行
// ( アプリケーション中でページ遷移する毎 )
// *************************************************
private void Page_Loaded(object sender, RoutedEventArgs e) {
Debug.WriteLine("Main Page_Loaded");
}
// *************************************************
// フレームに NextPage をセット
// *************************************************
private void Button_Click_1(object sender, RoutedEventArgs e) {
App.rootFrame.Content = App.nextPage;
}
}
}
|
|
【Win8 ストアアプリの最新記事】
- C# : HttpClient で Post と Get する汎用 static クラス
- Win8.1 ストアアプリ(JS) : Visual Studio 2013 で Three.js(v65) の WebGLRenderer の動作を確認しました
- WinJS ストア : Three.js を組み込んで、『画像を飛ばす』テンプレート( Bird.js を利用 )
- WinJS ストア : 『背景画像をチェンジする2画面アプリ』のテンプレート
- VS2012ストア(C#) : WebView テンプレート
- VS2012(C#)ストア : ListView Twitter 検索テンプレート
- Twitter API の自分のアプリのトークンを使って投稿するだけの class VS2012_Twitter
- Win8 ストア(C#) / PDF viewer sample (Windows 8.1)
- ストアアプリの TextBox のスクロールバー
- Win8 ストアアプリの、メモリ上にページを残す画面遷移と、前画面のコントロールの参照
- Win8 ストアアプリで、『選択肢を応答するダイアログ』を簡単に使うための MessageBox クラス
- Win8 ストアから Post 投稿
- Win8ストア XAML の AppBarButtonStyle のContent に指定する 16進数 Unicode の取得
- Win8 ストア : UrlEncode と UrlDecode
- Win8 ストア : HttpClient + XDocument で RSS の取得
- Win8 ストア : リストボックス テンプレート
- Win8 ストア : ファイルアクセス テンプレート
- Win8 ストア : ストアブランク テンプレート
- AppBar テンプレート / Win8 ストアアプリ(C#)
- Windows ストアアプリの AppBar を作成してテストする



NextPage
次画面は、LinearGradientBrush でグラデーションにしました。
App.xaml.cs
ページの設定は、Microsoft のテンプレートを無視しました。本来の WPF と同じような形でフレーム内のコンテンツを複数ページで切り替える形にしています。




