文章出處

上一篇為大家介紹了AppBar 的相關內容,本篇繼續介紹CommandBar 的使用方法。與AppBar 相比而言,CommandBar 在開發使用方面較為單一,在按鍵布局上分為主控區(Primary Commands)與輔控區(Secondary Commands),默認情況下,主控區顯示在菜單右側,輔控區在左側。

如果應用菜單欄中只包含AppBarButton、AppBarToggleButton、AppBarSeparator 這幾個控件,且沒有特殊布局格式要求,及可以使用CommandBar 控件。當應用尺寸變化時,CommandBar 也會隨之調整尺寸。

<Page.BottomAppBar>
    <CommandBar>
        <AppBarButton x:Uid="Camera" Icon="Camera" Label="Camera"/>
        <AppBarToggleButton x:Uid="Suffle" Icon="Shuffle" Label="Shuffle"/>
        <AppBarToggleButton x:Uid="Account" Icon="Account" Label="Account"/>
        <AppBarButton x:Uid="Like" Icon="Like" Label="Like"/>
        <AppBarButton x:Uid="Dislike" Icon="Dislike" Label="Dislike"/>

        <AppBarSeparator/>

        <AppBarButton x:Uid="Add" Icon="Add" Label="Add"/>
        <AppBarToggleButton x:Uid="Remove" Icon="Remove" Label="Remove"/>
        <AppBarButton x:Uid="Delete" Icon="Delete" Label="Delete"/>
    </CommandBar>
</Page.BottomAppBar>

image

如上面代碼,默認所有控件都是分配在主控區及菜單欄右側,將Add、Remove、Delete 按鍵放入輔控區是什么樣子呢,如下:

<Page.BottomAppBar>
    <CommandBar>
        <AppBarButton x:Uid="Camera" Icon="Camera" Label="Camera"/>
        <AppBarToggleButton x:Uid="Suffle" Icon="Shuffle" Label="Shuffle"/>
        <AppBarToggleButton x:Uid="Account" Icon="Account" Label="Account"/>
        <AppBarButton x:Uid="Like" Icon="Like" Label="Like"/>
        <AppBarButton x:Uid="Dislike" Icon="Dislike" Label="Dislike"/>

        <AppBarSeparator/>

        <CommandBar.SecondaryCommands>
            <AppBarButton x:Uid="Add" Icon="Add" Label="Add"/>
            <AppBarToggleButton x:Uid="Remove" Icon="Remove" Label="Remove"/>
            <AppBarButton x:Uid="Delete" Icon="Delete" Label="Delete"/>
        </CommandBar.SecondaryCommands>
    </CommandBar>
</Page.BottomAppBar>

image

如上圖所示,寫入SecondaryCommands 的按鍵被分配到了菜單欄左側。關于CommandBar 介紹就到這里,大家可以動手操練一下。


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()