2015-08-15 26 views
0

我是Windows手机浏览器的狂热粉丝,我想将类似的底栏移植到我的应用程序中。现在,我正在使用标准CommandBar在XAML中实现IE/Microsoft Edge底部栏

<Page.BottomAppBar> 
    <CommandBar> 
     <AppBarButton Icon="Go" Click="Go"/> 
     <CommandBar.SecondaryCommands> 
      <AppBarButton Icon="Setting" Label="Settings" Click="ShowSettings"/> 
     </CommandBar.SecondaryCommands> 
    </CommandBar> 
</Page.BottomAppBar> 

这样做会浪费屏幕空间,我真的想利用巴的剩余空间来添加类似的应用程序状态(到位边缘/ IE的地址栏),像下载/上传进展。不幸的是,CommandBar不允许引入诸如TextBlockProgressRing之类的内容。要使用这些控件,我们需要改为改为AppBar。但是,我不能使用CommandBar的功能,如添加3个点按钮来打开隐藏的按钮。

是否有一种简单的方法来实现这一点,即结合AppBar的灵活性和CommandBar的3点特征?

回答

1

CommandBar只接受继承ICommandBarElement接口的控件。

我们可以创建一个用户控件,其继承ICommandBarElement,只是做了一个小测试,而不优化代码,看看,看看是否有帮助:

public sealed partial class MyUserControl1 : UserControl, ICommandBarElement 
{ 
    public MyUserControl1() 
    { 
     this.InitializeComponent(); 
    } 
    private bool _IsCompact = true; 
    bool ICommandBarElement.IsCompact 
    { 
     get 
     { 
      return _IsCompact; 
     } 

     set 
     { 
      _IsCompact = value; 
     } 
    } 
} 

另外,用户控件XAML:

<UserControl 
x:Class="App10.MyUserControl1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:App10" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignWidth="400" Height="38.027"> 

<Grid> 
    <TextBlock Foreground="DarkBlue">asdsadasdasdasdasda</TextBlock> 
</Grid> 

然后我们在CommandBar中使用userControl,这里我们去: http://i.stack.imgur.com/Bgug9.png

注意:请进一步优化它,例如注册一些文本依赖项属性以启用接受数据绑定。

+0

任何想法如何推动文本对齐左侧的酒吧或拉伸控件采取像边缘的可用空间?我尝试过'Horizo​​ntalAlignment ='Stretch'',这在典型情况下使用,但在这种情况下不起作用。 –

0

根据documentation on MSDN可以使用CommandBar.Content属性,该属性对应于任何主要命令旁边的空白区域。要改变内容的对齐方式,您需要更改CommandBar.Horizo​​ntalContentAlignment属性。

<CommandBar HorizontalContentAlignment="Stretch"> 
     <AppBarButton Icon="Go" Click="Go"/> 
     <CommandBar.SecondaryCommands> 
      <AppBarButton Icon="Setting" Label="Settings" Click="ShowSettings"/> 
     </CommandBar.SecondaryCommands> 
     <CommandBar.Content> 
      <Grid> 
       <TextBox HorizontalAlignment="Stretch" 
        VerticalAlignment="Top" 
        Margin="12,8"/> 
      </Grid> 
     </CommandBar.Content> 
    </CommandBar> 

而作为Win10的建议是把命令栏内联,而不是使用Page.TopAppBar或Page.BottomAppBar属性。您可能仍然希望使用Page.BottomAppBar属性的一种情况是确保CommandBar在软件键盘出现时保持可见。