Windows 8 应用开发 - 应用栏
生活随笔
收集整理的這篇文章主要介紹了
Windows 8 应用开发 - 应用栏
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通過應用欄(AppBar)可以在需要時向用戶顯示各種應用命令。應用欄提供與用戶當前頁面或當前選定的內容相關的各種命令。默認情況下,應用欄處于隱藏狀態。當用戶沿屏幕邊緣從頂部或底部用手指劃動時會顯示應用欄,還可以通過單擊鼠標右鍵顯示。在用戶啟動命令、點擊應用界面或重復劃動手勢后,應用欄會自動消失。如果需要進行多選命令操作時,也可以以讓應用欄始終可見。
IC561717
新建應用欄 以下邊欄(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> image
兩個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); } } screenshot_11132012_230534
源碼下載
IC561717
新建應用欄 以下邊欄(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> image
兩個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); } } screenshot_11132012_230534
源碼下載
http://sdrv.ms/SSPQM2
本文轉自Gnie博客園博客,原文鏈接http://www.cnblogs.com/gnielee/archive/2012/11/13/windows8-app-develop-appbar.html,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的Windows 8 应用开发 - 应用栏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS编程建议——42:用好正则表达式静态
- 下一篇: java信息管理系统总结_java实现科