Windows 8 應用開發 – 應用程式列

來源:互聯網
上載者:User

     通過應用程式列(AppBar)可以在需要時向使用者顯示各種應用程式命令。應用程式列提供與使用者當前頁面或當前選定的內容相關的各種命令。預設情況下,應用程式列處於隱藏狀態。當使用者沿螢幕邊緣從頂部或底部用手指划動時會顯示應用程式列,還可以通過單擊滑鼠右鍵顯示。在使用者啟動命令、點擊應用介面或重複划動手勢後,應用程式列會自動消失。如果需要進行多選命令操作時,也可以以讓應用程式列始終可見。

建立應用程式列

以下側邊欄(BottomAppBar)為例,利用AppBar 控制項編寫一個具有文本編輯功能的應用程式列。

<Page.BottomAppBar>    <AppBar x:Name="BottomAppBar">        <Grid>            <Grid.ColumnDefinitions>                <ColumnDefinition Width="50*"/>                <ColumnDefinition Width="50*"/>            </Grid.ColumnDefinitions>            <StackPanel x:Name="LeftPanel" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">                <Button x:Name="Edit" Style="{StaticResource EditAppBarButtonStyle}" Click="Edit_Button_Click"/>                <Button x:Name="Save" Style="{StaticResource SaveAppBarButtonStyle}"/>                <Button x:Name="Delete" Style="{StaticResource DeleteAppBarButtonStyle}"/>            </StackPanel>            <StackPanel x:Name="RightPanel" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">                <Button x:Name="Refresh" Style="{StaticResource RefreshAppBarButtonStyle}"/>            </StackPanel>        </Grid>    </AppBar></Page.BottomAppBar>

     從上面代碼可以看出編寫應用程式列本身並沒有什麼複雜之處,而且應用程式列中使用按鍵的風格在Win8 應用中也都提供了。在項目工程Common 檔案夾中找到StandardStyles.xaml 裡面有很多注釋掉的ButtonStyle,在裡面找到你需要的提出來即可。

編輯應用程式列

     接下來,我們在應用介面中添加兩個CheckBox:一個用來將應用程式列固定,另一個用來新增或刪除應用程式列按鍵。

<StackPanel Orientation="Vertical" Grid.Row="1" Margin="120,50,0,0">    <CheckBox x:Name="IsSticky" Content="IsSticky" Click="IsSticky_Click" />    <CheckBox x:Name="AddHelpButton" Content="Add Help Button" Click="AddHelpButton_Click" /></StackPanel>

     兩個CheckBox 點擊事件代碼如下,當應用程式列IsSticky 屬性啟用後,只能通過划動下邊螢幕或滑鼠右鍵將取消顯示。

private void IsSticky_Click(object sender, RoutedEventArgs e){    CheckBox cb = sender as CheckBox;    AppBar ap = pageRoot.FindName("BottomAppBar") as AppBar;    if (ap != null)    {        ap.IsSticky = (bool)cb.IsChecked;    }}private void AddHelpButton_Click(object sender, RoutedEventArgs e){    CheckBox cb = sender as CheckBox;    if ((bool)cb.IsChecked)    {        Button helpButton = new Button();        helpButton.Name = "Help";        helpButton.Style = App.Current.Resources["HelpAppBarButtonStyle"] as Style;        RightPanel.Children.Add(helpButton);    }    else    {        RightPanel.Children.RemoveAt(1);    }}

源碼下載

http://sdrv.ms/SSPQM2

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.