====== 020 アプリケーションバーを使用する ====== {{:wiki:windowsphone:7.1:tips:w_phone_020_001.png?200|}} ===== 概要 ===== 画面の下部に表示されるメニューバーを表示します。WindowsPhoneではこれをアプリケーションバーと呼びます。 ==== ポイント ==== システムが提供するアイコンの場所は「C:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Icons\dark」にある。追加したアイコンはそれぞれ、プロパティの設定から「ビルドアクション」をコンテンツに変更しないと適用されない。 ==== MainPage.xaml ==== ==== MainPage.xaml.cs ==== using System; using System.Collections.Generic; 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 Microsoft.Phone.Controls; using Microsoft.Phone.Shell; namespace BaseApp { public partial class MainPage : PhoneApplicationPage { ApplicationBar appBar = null; // コンストラクター public MainPage() { InitializeComponent(); // 初期化完了後に呼ばれるメソッドの登録。 Loaded += OnLoaded; } // 初期化完了後に呼ばれるメソッド。 void OnLoaded(object sender, RoutedEventArgs args) { // アプリケーションバーの生成。 ApplicationBar = new ApplicationBar(); ApplicationBar.IsMenuEnabled = true; ApplicationBar.IsVisible = true; ApplicationBar.Opacity = 1.0; // 追加ボタンの作成。 ApplicationBarIconButton addButton = new ApplicationBarIconButton( new Uri("/Images/appbar.add.rest.png", UriKind.Relative)); addButton.Text = "追加"; addButton.Click += new EventHandler(AddButton_Click); ApplicationBar.Buttons.Add(addButton); // 削除ボタンの作成。 ApplicationBarIconButton removeButton = new ApplicationBarIconButton( new Uri("/Images/appbar.delete.rest.png", UriKind.Relative)); removeButton.Text = "削除"; removeButton.Click += new EventHandler(RemoveButton_Click); ApplicationBar.Buttons.Add(removeButton); } //追加ボタンの処理 void AddButton_Click(object sender, EventArgs e) { // todo } //削除ボタンの処理 void RemoveButton_Click(object sender, EventArgs e) { // todo } } }