ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
Windows8(C#) ストアアプリ : AppBar テンプレート
日時: 2013/05/03 09:25
名前: lightbox





MainPage.xaml
拡張子:
<Page
	x:Class="LBOX_AppBar.MainPage"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="using:LBOX_AppBar"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d">
	
	<Page.Resources>
		<local:TextResource
			x:Key="GlobalText"
			PageTitle="AppBar テンプレート"	/>
	</Page.Resources>

	<!--AppBar の定義-->
	<Page.BottomAppBar>
		<AppBar>
			<Grid x:Name="AppBarGrid">
				<Grid.ColumnDefinitions>
					<ColumnDefinition/>
					<ColumnDefinition/>
				</Grid.ColumnDefinitions>
				
				<StackPanel
					x:Name="LeftBar"
					Orientation="Horizontal"
					HorizontalAlignment="Left"
					>

					<!--StandardStyles に定義されたスタイルをそのまま適用する-->
					
					<!--設定ボタン-->
					<Button
						x:Name="SettingButton"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch"
						Style="{StaticResource SettingsAppBarButtonStyle}"
						Click="SettingButton_Click"
						/>

					<!--削除ボタン-->
					<Button
						x:Name="DeleteButton"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch"
						Style="{StaticResource DeleteAppBarButtonStyle}"
						Click="DeleteButton_Click"
						/>

					<!--お気に入りボタン-->
					<Button
						x:Name="FavoriteButton"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch"
						Style="{StaticResource FavoriteAppBarButtonStyle}"
						Click="FavoriteButton_Click"
						/>

				</StackPanel>
				
				<StackPanel x:Name="RightBar"
					Grid.Column="1"
					HorizontalAlignment="Right"
					Orientation="Horizontal"
					>

					<!-- 保存ボタンを定義時に、表示文字列を変更する-->
					<Button
						x:Name="SaveButton"
						AutomationProperties.Name="保存"
						Grid.Column="1"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch"
						Style="{StaticResource SaveAppBarButtonStyle}"
						Click="SaveButton_Click"
						/>
					
					<!--メールボタン-->
					<Button
						x:Name="MailButton"
						Grid.Column="1"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch"
						Style="{StaticResource MailAppBarButtonStyle}"
						Loaded="MailButton_Loaded" Click="MailButton_Click" 
						/>

				</StackPanel>
			</Grid>
		</AppBar>
	</Page.BottomAppBar>

	<!--画面定義-->
	<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
		<Border BorderBrush="#FF999999" BorderThickness="3" HorizontalAlignment="Left" Height="546" Margin="76,126,0,0" VerticalAlignment="Top" Width="1122" Background="#FF323232" CornerRadius="20"/>
		<TextBlock
			HorizontalAlignment="Left"
			Height="61"
			Margin="76,60,0,0"
			TextWrapping="Wrap"
			Text="{Binding Source={StaticResource GlobalText},Path=PageTitle}"
			VerticalAlignment="Top"
			Width="1090"
			FontSize="40"
			FontWeight="Bold"
			FontFamily="Meiryo"
			/>

	</Grid>
	
</Page>
メンテナンス

MainPage.xaml.cs ( No.1 )
日時: 2013/05/03 09:24
名前: lightbox


日時: 2013/05/03 09:24
名前: lightbox
拡張子:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
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;

//名前空間
namespace LBOX_AppBar
{
	//クラス
	public sealed partial class MainPage : Page
	{
		//コンストラクタ
		public MainPage()
		{
			this.InitializeComponent();
		}

		// *************************************************
		// このページがフレームに表示されるときに呼び出されます。
		// *************************************************
		protected override void OnNavigatedTo(NavigationEventArgs e)
		{
		}

		// *************************************************
		//設定ボタン
		// *************************************************
		private void SettingButton_Click(object sender, RoutedEventArgs e)
		{

		}

		// *************************************************
		//削除ボタン 
		// *************************************************
		private void DeleteButton_Click(object sender, RoutedEventArgs e)
		{

		}

		// *************************************************
		//お気に入りボタン
		// *************************************************
		private void FavoriteButton_Click(object sender, RoutedEventArgs e)
		{

		}

		// *************************************************
		//保存ボタン
		// *************************************************
		private async void SaveButton_Click(object sender, RoutedEventArgs e)
		{
			var messageDialog = new MessageDialog("データを保存しますか?","AppBarテンプレート");

			// OK ボタンのイベントを定義する
			var OK_Handler = new UICommandInvokedHandler(this.CommandInvokedHandler);
			var OK_Command = new UICommand("OK", OK_Handler) { Id = 0 };
			messageDialog.Commands.Add(OK_Command);

			// Cancel ボタンのイベントを定義する
			messageDialog.Commands.Add(
				new UICommand(
					"Cancel",
					new UICommandInvokedHandler(this.CommandInvokedHandler)
					) { Id = 1 }
				);

			// 無名のイベントで、アプリケーションを終了する
			messageDialog.Commands.Add(
				new UICommand(
					"アプリ終了",
					(Command) =>
					{
						// アプリケーション終了
						App.Current.Exit();
					}
					) { Id = 2 }
				);

			// Enter キーで反応するデフォルトボタン
			messageDialog.DefaultCommandIndex = 0;
			// ESC キーで反応するキャンセルボタン
			messageDialog.CancelCommandIndex = 1;

			await messageDialog.ShowAsync();
		}

		// *************************************************
		//メールボタン
		// *************************************************
		private void MailButton_Click(object sender, RoutedEventArgs e)
		{

		}

		// *************************************************
		// メールボタンをロード時に、表示文字列を変更する
		// *************************************************
		private void MailButton_Loaded(object sender, RoutedEventArgs e)
		{
			AutomationProperties.SetName(sender as Button, "メール");
		}

	}
}
{ Id = 0 } は、オブジェクト初期化子によるオブジェクトのプロパティに対する初期設定です。
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
MainPageB.cs ( No.2 )
日時: 2013/05/03 09:21
名前: lightbox
このソースコードは、『partial』 の機能である同一クラスを複数ソースコードで定義する方法のサンプルです
拡張子:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
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;

namespace LBOX_AppBar
{
	public sealed partial class MainPage : Page
	{

		private void CommandInvokedHandler(IUICommand command)
		{
			Debug.WriteLine("保存ボタンがクリックされました");
			Debug.WriteLine("応答ボタンのテキストは《" + command.Label + "》です");
		}

	}

}
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
TextResource.cs ( No.3 )
日時: 2013/05/03 06:39
名前: lightbox
XAML 内で、テキストデータをバインドするに必要なクラスです
拡張子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LBOX_AppBar
{
	public class TextResource
	{
		public string PageTitle { get; set; }
	}
}
このアーティクルの参照用URLをクリップボードにコピー メンテナンス