Windows Phone8.1中的CommandBar

妖狐艹你老母 2022-08-06 02:26 280阅读 0赞

开篇之前:

若对Windows 8.1的相关Appbar和CommandBar控件感兴趣,强烈推荐王磊老师的博客园

链接:重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar

以及不知道名字的博主对WP8.1中Appbar阐述的一篇文章:http://www.dotblogs.com.tw/eternaltung/archive/2014/05/07/wpappbar.aspx

好了,下面就Windows Phone8.1,以及看了以上两位的文章之后,列举下我的感悟:

WP8.1中只有BottomAppBar,没有TopAppBar。因为就人体体验和美感来说,将Appbar设计到手机到上方并不人性化。

CommandBar控件有几个很有用也很让人糊涂的属性

1.ClosedDisplayMode

设为Minimal则将Appbar隐藏到最小;设为Compact则将Appbar正常显示,如下图所示:

20141215210114291 20141215210131029

2.PrimaryCommands和SecondaryCommands属性

Windows 8.1中两个属性就是字面上的意思,一前一后,从左往右排列

Windows Phone 8.1中前者还是按照从左往右排序的,而后者并不是继续排列下去,而是变成MenuItem列表的形式,如下图区别:

20141215211945122

  1. <span style="font-size:18px;"><Page.BottomAppBar>
  2. <CommandBar x:Name="commonBar" IsSticky="True" ClosedDisplayMode="Compact">
  3. <AppBarToggleButton Icon="Like" Label="Like"/>
  4. <AppBarToggleButton Icon="Dislike" Label="Dislike"/>
  5. <AppBarButton Icon="Library" Label="Library"/>
  6. <AppBarButton Icon="Stop" Label="Stop"/>
  7. <!--以上部分没写在CommandBar.PrimaryCommands中,但默认自动添加进其中-->
  8. <CommandBar.SecondaryCommands>
  9. <AppBarButton Icon="Like" Label="Like"/>
  10. <AppBarButton Icon="Dislike" Label="Dislike"/>
  11. <AppBarButton Icon="Library" Label="Library"/>
  12. <AppBarButton Icon="Stop" Label="Stop"/>
  13. </CommandBar.SecondaryCommands>
  14. </CommandBar>
  15. </Page.BottomAppBar></span>

3.IsSticky和IsOpen属性

这部分请参考微软MSDN上给出的解释,很详细很好

链接:AppBar Class

IsOpen属性:获取或设置指示AppBar是否可见的值

IsSticky属性:获取或设置指示 AppBar是否在光消散时不关闭的值

false - 显示 AppBar 后,如果用户触摸了非 AppBar 区域则 AppBar 会自动隐藏,默认值

true - 显示 AppBar 后,即使用户触摸了非 AppBar 区域,AppBar 也不会自动隐藏,需要通过底部边缘手势或者右键

或者win+z或者api使其隐

默认情况下,应用程序栏会在用户在应用程序栏之外的任何位置与您的应用程序交互时关闭。这称为光消散。要使命

令可见,可以通过将 IsSticky 属性设置为 true 来更改关闭

模式。当应用程序条是便笺,并且仅在用户右击、按下 Windows+Z 或从屏幕的顶边或下边重击时关闭

OnClosed方法:在 AppBar从可见更改为隐藏时调用

OnOpened方法:Invoked when the AppBar changes from hidden to visible, or is first displayed

Closed事件:在 AppBar 从可见更改为隐藏时发生

Opened事件:在 AppBar 从隐藏更改为可见时发生

发表评论

表情:
评论列表 (有 0 条评论,280人围观)

还没有评论,来说两句吧...

相关阅读