2016-03-19 2 views
0

В настоящее время я работаю в Windows 10, и я работаю над элементами управления AppBar и Command Bar. Я создал Appbar, внутри которого я добавил commandBar, который содержит кнопку и панель приложения. Теперь проблема заключается в том, что он показывает больше значков для командных и AppBar. Можете ли вы предложить, как я могу удалить это?Как удалить панель приложения в Windows 10?

Мой код ниже

CommandBar commandBar = new CommandBar(); 
if (this.BottomAppBar == null) 
{ 
     this.BottomAppBar = new AppBar(); 
     this.BottomAppBar.IsOpen = true; 
     this.BottomAppBar.IsSticky = true; 
} 

commandBar.PrimaryCommands.Clear(); 
commandBar.IsSticky = true; 
commandBar.IsOpen = true; 
commandBar.ClosedDisplayMode = AppBarClosedDisplayMode.Compact; 
AppBarButton appBarButton = new AppBarButton(); 
appBarButton.Foreground = MCSExtensions.GetColorFromHex(foreground_color); 
appBarButton.Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Images/submit.png", UriKind.Absolute) }; 
appBarButton.Label = formButton.B_NAME; 

commandBar.PrimaryCommands.Add(appBarButton); 
this.BottomAppBar.Content=commandBar; 

выше генерирует следующий вывод

enter image description here

То, что я на самом деле хочу оставляется боковую панель, которая CommandBar, а не серая часть. Может кто-нибудь предположить, что я делаю неправильно? Я также попытался просто добавить CommmandBar внутри сетки, но он вообще не отображался.

Update

CommandBar commandBar=new CommmandBar(); 
commandBar.IsOpen=true; 
commandBar.IsSticky=true; 
commandBar.ClosedDisplayMode=AppBarClosedDisplatMode.Compact; 
AppBarButton appBarButton = new AppBarButton(); 
appBarButton.Foreground = MCSExtensions.GetColorFromHex(foreground_color); 
appBarButton.Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Images/submit.png", UriKind.Absolute) }; 
appBarButton.Label = formButton.B_NAME; 

commandBar.PrimaryCommands.Add(appBarButton); 
pageLayoutRootGrid.Children.Add(commandBar); 

Я также попытался добавить StackPanel в AppBar, как показано ниже, но не дает должных результатов.

if (this.BottomAppBar == null) 
{ 
     this.BottomAppBar = new AppBar(); 
     this.BottomAppBar.IsOpen = true; 
     this.BottomAppBar.IsSticky = true; 
} 
StackPanel appBarPanel=new StackPanel(); 
appBarPanel.Orientation=Orientation.Horizontal;   
AppBarButton appBarButton = new AppBarButton(); 
appBarButton.Foreground = MCSExtensions.GetColorFromHex(foreground_color); 
appBarButton.Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Images/submit.png", UriKind.Absolute) }; 
appBarButton.Label = formButton.B_NAME; 

appBarPanel.Children.Add(appBarButton); 
this.BottomAppBar.Content=appBarPanel; 

ответ

2

Для XAML:

<Page.BottomAppBar> 
    <CommandBar> 
     <CommandBar.PrimaryCommands> 
      <AppBarButton Icon="Accept"/> 
     </CommandBar.PrimaryCommands> 
    </CommandBar> 
</Page.BottomAppBar> 

эта линия сделать ваш UI перепутались:

this.BottomAppBar = new AppBar();

, как вы можете видеть из моего XAML, создать только 1 CommandBar внутри BottomAppBar

Редактировать: если вы хотите использовать код, используйте это:

var commandBar = new CommandBar(); 
commandBar.PrimaryCommands.Add(new AppBarButton() { Label = "test" }); 
commandBar.VerticalAlignment = VerticalAlignment.Bottom; 
this.root.Children.Add(commandBar); 

UPDATE

Полный код XAML:

<Page 
    x:Class="CommandBarSample.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:CommandBarSample" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" x:Name="root"> 

    </Grid> 
</Page> 

Код позади:

public sealed partial class MainPage : Page 
    { 
     public MainPage() 
     { 
      this.InitializeComponent(); 



      var commandBar = new CommandBar(); 
      commandBar.VerticalAlignment = VerticalAlignment.Bottom; 
      var appBarButton = new AppBarButton() { Icon = new SymbolIcon(Symbol.Accept), Label = "Accept" }; 
      commandBar.PrimaryCommands.Add(appBarButton); 

      root.Children.Add(commandBar); 
     } 
    } 
+0

Но я хочу, чтобы создать CommandBar динамически как то, что я добавил в моем вопросе не используя Xaml –

+0

Я добавил образец кода для его динамического создания – thang2410199

+0

корень означает страницу справа? –

Смежные вопросы