Windows 8 应用开发 - 应用栏
生活随笔
收集整理的這篇文章主要介紹了
Windows 8 应用开发 - 应用栏
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
通過應(yīng)用欄(AppBar)可以在需要時(shí)向用戶顯示各種應(yīng)用命令。應(yīng)用欄提供與用戶當(dāng)前頁面或當(dāng)前選定的內(nèi)容相關(guān)的各種命令。默認(rèn)情況下,應(yīng)用欄處于隱藏狀態(tài)。當(dāng)用戶沿屏幕邊緣從頂部或底部用手指劃動(dòng)時(shí)會(huì)顯示應(yīng)用欄,還可以通過單擊鼠標(biāo)右鍵顯示。在用戶啟動(dòng)命令、點(diǎn)擊應(yīng)用界面或重復(fù)劃動(dòng)手勢(shì)后,應(yīng)用欄會(huì)自動(dòng)消失。如果需要進(jìn)行多選命令操作時(shí),也可以以讓應(yīng)用欄始終可見。
IC561717
新建應(yīng)用欄 以下邊欄(BottomAppBar)為例,利用AppBar 控件編寫一個(gè)具有文本編輯功能的應(yīng)用欄。
<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> 從上面代碼可以看出編寫應(yīng)用欄本身并沒有什么復(fù)雜之處,而且應(yīng)用欄中使用按鍵的風(fēng)格在Win8 應(yīng)用中也都提供了。在項(xiàng)目工程Common 文件夾中找到StandardStyles.xaml 里面有很多注釋掉的ButtonStyle,在里面找到你需要的提出來即可。
編輯應(yīng)用欄 接下來,我們?cè)趹?yīng)用界面中添加兩個(gè)CheckBox:一個(gè)用來將應(yīng)用欄固定,另一個(gè)用來新增或刪除應(yīng)用欄按鍵。
<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
兩個(gè)CheckBox 點(diǎn)擊事件代碼如下,當(dāng)應(yīng)用欄IsSticky 屬性激活后,只能通過劃動(dòng)下邊屏幕或鼠標(biāo)右鍵將取消顯示。
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
新建應(yīng)用欄 以下邊欄(BottomAppBar)為例,利用AppBar 控件編寫一個(gè)具有文本編輯功能的應(yīng)用欄。
<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> 從上面代碼可以看出編寫應(yīng)用欄本身并沒有什么復(fù)雜之處,而且應(yīng)用欄中使用按鍵的風(fēng)格在Win8 應(yīng)用中也都提供了。在項(xiàng)目工程Common 文件夾中找到StandardStyles.xaml 里面有很多注釋掉的ButtonStyle,在里面找到你需要的提出來即可。
編輯應(yīng)用欄 接下來,我們?cè)趹?yīng)用界面中添加兩個(gè)CheckBox:一個(gè)用來將應(yīng)用欄固定,另一個(gè)用來新增或刪除應(yīng)用欄按鍵。
<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
兩個(gè)CheckBox 點(diǎn)擊事件代碼如下,當(dāng)應(yīng)用欄IsSticky 屬性激活后,只能通過劃動(dòng)下邊屏幕或鼠標(biāo)右鍵將取消顯示。
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
本文轉(zhuǎn)自Gnie博客園博客,原文鏈接http://www.cnblogs.com/gnielee/archive/2012/11/13/windows8-app-develop-appbar.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的Windows 8 应用开发 - 应用栏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS编程建议——42:用好正则表达式静态
- 下一篇: Arduino数字引脚作为GPIO的使用