Multiple AppBar/CommandBar's

前端 未结 3 912
借酒劲吻你
借酒劲吻你 2020-12-10 09:05

Back in Windows Phone 8, I was able to to use multiple AppBar, swapping them on certain pivot pages but In Windows Phone 8.1, I\'m not sure how to do this or is this even po

3条回答
  •  一整个雨季
    2020-12-10 09:41

    In WP8.1 RT, you have a property BottomAppBar of your Page. It works pretty much the same (apart it's extended) as old ApplicationBar - you can set it with CommandBar. I've created my command bars in code and it works, you can try like this:

    // prepare your CommandBars - run method somewhere in the constructor of the page:
    CommandBar firstBar;
    CommandBar secondBar;
    
    private void PrepareAppBars()
    {
        firstBar = new CommandBar();
        firstBar.IsOpen = true;
        AppBarButton FirstBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/first.png") } };
        FirstBtn.Label = "First";
        FirstBtn.Click += FirstBtn_Click;
        FirstBtn.IsEnabled = true;
        // Similar for second button
        AppBarButton SecondBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/second.png") } };
    
        firstBar.PrimaryCommands.Add(FirstBtn);
        firstBar.PrimaryCommands.Add(SecondBtn);
    
        // define also SecondaryCommands
    
        // simlar secondBar
        secondBar = new CommandBar();
        secondBar.IsOpen = true;
        // ...
    }
    
    // then you can surely switch them like this:
    
    private void MainPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        switch (MainPivot.SelectedIndex)
        {
            case 0:
                BottomAppBar = firstBar ;
                break;
            case 1:
                BottomAppBar = secondBar ;
                break;
        }
    }
    

提交回复
热议问题