/*
* Copyright (C) 2013 FooProject
* * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see .
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.ApplicationSettings;
using Windows.UI.Popups;
// 空のアプリケーション テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234227 を参照してください
namespace Test
{
///
/// 既定の Application クラスを補完するアプリケーション固有の動作を提供します。
///
sealed partial class App : Application
{
bool SettingRegistored;
Popup Popup;
///
/// 単一アプリケーション オブジェクトを初期化します。これは、実行される作成したコードの
/// 最初の行であり、main() または WinMain() と論理的に等価です。
///
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
///
/// アプリケーションがエンド ユーザーによって正常に起動されたときに呼び出されます。他のエントリ ポイントは、
/// アプリケーションが特定のファイルを開くために呼び出されたときに
/// 検索結果やその他の情報を表示するために使用されます。
///
/// 起動要求とプロセスの詳細を表示します。
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
// ウィンドウに既にコンテンツが表示されている場合は、アプリケーションの初期化を繰り返さずに、
// ウィンドウがアクティブであることだけを確認してください
if (rootFrame == null)
{
// ナビゲーション コンテキストとして動作するフレームを作成し、最初のページに移動します
rootFrame = new Frame();
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: 以前中断したアプリケーションから状態を読み込みます。
}
// フレームを現在のウィンドウに配置します
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// ナビゲーション スタックが復元されていない場合、最初のページに移動します。
// このとき、必要な情報をナビゲーション パラメーターとして渡して、新しいページを
// 構成します
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
if (!this.SettingRegistored)
{
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
this.SettingRegistored = true;
}
// 現在のウィンドウがアクティブであることを確認します
Window.Current.Activate();
}
void OnCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs eventArgs)
{
var handler = new UICommandInvokedHandler(OnSettingsCommand);
var policyCommand = new SettingsCommand("setting", "設定", handler);
eventArgs.Request.ApplicationCommands.Add(policyCommand);
}
private void OnSettingsCommand(IUICommand command)
{
var settingsCommand = (SettingsCommand)command;
switch (settingsCommand.Id.ToString())
{
case "setting":
ShowSettingsFlyout();
break;
}
}
void ShowSettingsFlyout()
{
var flyout = new Test.SettingsFlyout1();
flyout.Show();
}
///
/// アプリケーションの実行が中断されたときに呼び出されます。アプリケーションの状態は、
/// アプリケーションが終了されるのか、メモリの内容がそのままで再開されるのか
/// わからない状態で保存されます。
///
/// 中断要求の送信元。
/// 中断要求の詳細。
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: アプリケーションの状態を保存してバックグラウンドの動作があれば停止します
deferral.Complete();
}
}
}