2016-03-19 7 views
0

私は現在Windows 10で作業しており、AppBarとCommand Barコントロールを操作しています。内部にAppbarを作成し、その内部にcommandbarを追加し、app barボタンを追加しました。今問題は、commandBarとAppBarのアイコンの数が増えていることです。どうすればこの問題を取り除くことができますか?Windows 10でappbar moreを削除するには?

マイコード

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

を生成しているコマンドバーで、左サイドバーではなく、灰色の部分です。誰かが私が間違っていることを提案することはできますか?私もグリッドの中にCommmandBarを追加しようとしましたが、全く表示されませんでした。

更新

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を追加することなく、適切な結果を与えていない試してみました。 XAMLの場合

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

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

このラインはあなたのUIが台無しにする:あなたは私のXAMLから見ることができるよう

this.BottomAppBar = new AppBar();

は、

BottomAppBar内のみ1コマンドバーを作成します

編集:コードを使用する場合は、次のようにします。

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

しかし、私は動的に私は私の質問にはない追加もののようにコマンドバーを作成したいですXamlを使用して –

+0

動的に作成するコードサンプルを追加しました。 – thang2410199

+0

ルートはページの権利を意味しますか? –

関連する問題