SkyDrive へ移動
ダウンロードしたテンプレートは、『C:\Users\ユーザー名\Documents\Visual Studio 2012\Templates\ProjectTemplates\Visual C#\Windows Store』に保存します。
Windows Store フォルダは最初は存在しないので作成します( 好きな名前のフォルダでも Visual Studio から利用できます )
ソースコード表示
仕様
❶ Page.Resources で XAML 内で利用する文字列を定義
❷ AppBar を XAML で定義
❸ ボタンを左側3つ、右側2つ定義
❹ それぞれのボタンにイベントを定義
❺ 保存ボタンのイベントで、MessageDialog の利用サンプルを実装
❻ MessageDialog のイベントを別のソースコードに定義( partial )
❼ TextResource.cs に、StaticResource 用のクラスを定義
❽ AutomationProperties を XAML とコードで使用して、ボタンの文字列を動的に変更
<Page.Resources>
<local:TextResource
x:Key="GlobalText"
PageTitle="AppBar テンプレート" />
</Page.Resources>
<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"
/>
Page.Resources 内で定義している、local:TextResource は、XAML 内でクラスからインスタンスを作成する方法です。作成されたオブジェクトは、XAML 内で(ここでは) GlobalText の名前で参照されて利用されます。
( local は、『xmlns:local="using:LBOX_AppBar"』で定義 )
PageTitle="AppBar テンプレート" の記述では、TextResource クラスに定義されたプロパティ(PageTitle)にデータをセットしています。そして、利用側では Binding によって、オブジェクトの設定済みのプロパティを参照しています。
public class TextResource
{
public string PageTitle { get; set; }
}
AutomationProperties
ボタンの文字列は、Style に定義した『StaticResource SaveAppBarButtonStyle』によって決定していますが、もともとのボタンのテキストでは無いので、AutomationProperties 経由で変更します。
<Button
x:Name="SaveButton"
AutomationProperties.Name="保存"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{StaticResource SaveAppBarButtonStyle}"
Click="SaveButton_Click"
/>
-----------------------------------------------------------------
// *************************************************
// メールボタンをロード時に、表示文字列を変更する
// *************************************************
private void MailButton_Loaded(object sender, RoutedEventArgs e)
{
AutomationProperties.SetName(sender as Button, "メール");
}