1

私は C# で開発された Windows ストア アプリを持っています。その中にいくつかのページがあり、それらの間のナビゲーションは Page.TopAppBar を介して行われます。このバーの共有バージョンを作成する方法が見つからないので、すべてのページに xaml と関連するコード ビハインドのコピーを含めることを余儀なくされました。

私が考えることができる唯一のことは、各ページから呼び出すことができるコードビハインドを使用して動的に作成することですが、可能であればXamlでのオーサリングのシンプルさを維持したいと思います。 Page.TopAppBarProperty は読み取り専用であり、コード ビハインドから設定することはできません。

何か案は?

4

1 に答える 1

2

多分このトリックはあなたを助けるでしょう:

AppBar トリック

コード ビハインドから AppBar を変更する方法のサンプルを次に示します。

protected async override void OnNavigatedTo(NavigationEventArgs e)
   {
            rootPage =  e.Parameter as MainPage;
            bottomAppBarPnl = rootPage.FindName("bottomAppBar") as StackPanel;

            if(bottomAppBarPnl != null)
            {               
             // Create the button to add             
             newCust = new Button();               
             newCust.Content = "New Customer";              
             newCust.Click += new RoutedEventHandler(newCust_Click);               
            // Add the button to the AppBar               
            bottomAppBarPnl.Children.Add(newCust);

            }

        }
于 2013-01-12T14:14:10.970 に答える