Windows 8風格應用開發入門 二十四 App Bar構建

來源:互聯網
上載者:User

構建應用程式列的目的的顯示導航、命令和始終隱藏不需要的使用的工具。我們可以把應用程式列放在頁面 頂部或底部或同時存在頂部和底部。

預設情況在AppBar是隱藏的,當使用者單擊右鍵、按下Win+Z 、或從螢幕的頂部或底部邊緣輕鬆時可顯示或關閉AppBar。當然我們也可以通過編程的方式將AppBar設 置為當使用者做選擇或與應用互動時顯示。

構建AppBar基本步驟

通常我們構建一個應用的 AppBar,只需要三步就可以完成:

如何構建AppBar

應用中添加AppBar,需要將AppBar控制項指定給Page的TopAppBar或 BottomAppBar屬性。

XAML代碼可如下:

<Page.BottomAppBar>                  <AppBar x:Name="bottomAppBar" Padding="10,0,10,0">                      <Grid>                          <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">                              <Button Style="{StaticResource EditAppBarButtonStyle}" />                              <Button Style="{StaticResource RemoveAppBarButtonStyle}" />                              <Button Style="{StaticResource AddAppBarButtonStyle}" />                          </StackPanel>                          <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">                              <Button Style="{StaticResource RefreshAppBarButtonStyle}" />                              <Button Style="{StaticResource HelpAppBarButtonStyle}" />                          </StackPanel>                      </Grid>                  </AppBar>          </Page.BottomAppBar>

XAML代碼中引用的資源樣式可以在應用程式解決方案的Common 檔案夾中StandardStyles.xaml檔案中找到。

運行效果:

若我們想在載入頁面時開啟AppBar,可以在XAML代碼中將AppBar控制項的IsOpen屬性值設定為true, 也可以在C#代碼中控制開啟AppBar。

private void OpenButton_Click(object sender, RoutedEventArgs e)          {              topAppBar.IsOpen = true;          }

當使用者在應用的AppBar以外任何位置進行互動時,預設情況會解除AppBar進行隱藏。我們可 以將IsSticky屬性值設定為true來改變解除模式。

此時使用者只有右擊、按下Win+Z、或從螢幕的 頂部或底部邊緣輕掃時才會隱藏AppBar。

private void StickyButton_Click(object sender, RoutedEventArgs e)          {              bottomAppBar.IsSticky = true;          }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.