手把手玩转win8开发系列课程(14)

简介:

这节的议程就是——添加appbar

appbar是出现在哪儿了,出现在屏幕的底部。他能使用户能用手势或者使用鼠标操作程序。metro UI 重点是在主要的控件使用许多控件,使其用户使用win8电脑更加的方便。而appBar使其用户体验更好。在这节中,我将告诉你如何定义和填充app Bar。

在界面的顶部有一个类似的控件,叫做navbar。这使其程序中,能够互相导航。 至于如何创建 使用navbar ,我将在后续文章详细的介绍。

定义一个appBar

我将用最简单的方法创建一个AppBar.下面源代码就是创建一个appBar:


 1 <Page
 2   x:Class="MetroGrocer.Pages.ListPage"
 3   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 4   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 5   xmlns:local="using:MetroGrocer.Pages"
 6   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 7   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 8   mc:Ignorable="d">
 9   <Grid Background="{StaticResource AppBackgroundColor}">
10     <Grid.RowDefinitions>
11       <RowDefinition/>
12       <RowDefinition/>
13     </Grid.RowDefinitions>
14     <Grid.ColumnDefinitions>
15       <ColumnDefinition/>
16       <ColumnDefinition/>
17     </Grid.ColumnDefinitions>
18     <StackPanel Grid.RowSpan="2">
19       <TextBlock Style="{StaticResource HeaderTextStyle}" Margin="10"
20             Text="Grocery List"/>
21       <ListView x:Name="groceryList" Grid.RowSpan="2"
22         ItemsSource="{Binding GroceryList}"
23         ItemTemplate="{StaticResource GroceryListItemTemplate}"
24         SelectionChanged="ListSelectionChanged" />
25     </StackPanel>
26     <StackPanel Orientation="Vertical" Grid.Column="1">
27       <TextBlock Style="{StaticResource HeaderTextStyle}" Margin="10"
28             Text="Item Detail"/>
29       <Frame x:Name="ItemDetailFrame"/>
30     </StackPanel>
31     <StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="1">
32       <TextBlock Style="{StaticResource HeaderTextStyle}" Margin="10"
33             Text="Store Detail"/>
34     </StackPanel>
35   </Grid>
36      <!--一个appbar控件定义的源代码-->
37   <Page.BottomAppBar>
38     <AppBar>
39       <Grid>
40           <!--Column 的定义-->
41         <Grid.ColumnDefinitions>
42           <ColumnDefinition />
43           <ColumnDefinition />
44         </Grid.ColumnDefinitions>
45          <!--垂直的显示-->
46         <StackPanel Orientation="Horizontal" Grid.Column="0"
47               HorizontalAlignment="Left">
48             <!--AppBar Button 控件 AppBarButtonClick 事件 -->
49           <Button x:Name="AppBarDoneButton"
50               Style="{StaticResource DoneAppBarButtonStyle}"
51               IsEnabled="false"
52               Click="AppBarButtonClick"/>
53         </StackPanel>
54         <StackPanel Orientation="Horizontal" Grid.Column="1"
55               HorizontalAlignment="Right">
56           <Button x:Name="AppBarAddButton"
57               Style="{StaticResource AddAppBarButtonStyle}"
58               AutomationProperties.Name="New Item"
59               Click="AppBarButtonClick"/>
60           <Button x:Name="AppBarStoresButton"
61               Style="{StaticResource StoresAppBarButton}"
62               Click="AppBarButtonClick"/>
63           <Button x:Name="AppBarZipButton"
64               Style="{StaticResource HomeAppBarButtonStyle}"
65               AutomationProperties.Name="Zip Code"
66               Click="AppBarButtonClick"/>
67         </StackPanel>
68       </Grid>
69     </AppBar>
70   </Page.BottomAppBar>
71 </Page>

为了创建appBar,我不得不创建一个appBar控件。因此,这创造appbar及其内容和属性包含了bottom Bar.

你可以创建一个通过类似方法在底部创建一个NavBar.

appbar工具条包含buttons按钮,这么做的规定是有按钮, 当前选择的显示在appBar左边,无选择的项目显示在右边。(也就是说,在win8的Consumer Preview版本中,这个用户体验的原则不完全,这将会正式版本会改变这个用户体验的原则)。

接下来的篇幅,我将会在AppBar 控件中添加Grid布局控件。这个Grid控件有1行2列。每列有一个stackpanel。 在appBar添加Button有两种方法。你可以选择在standardstyles.xaml定义,或者直接添加。

如何添加appBarButton,我将会在下面的篇幅中介绍。


目录
相关文章
|
10天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1210 5
|
9天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
1172 87
|
9天前
|
云栖大会
阿里云云栖大会2025年9月24日开启,免费申请大会门票,速度领取~
2025云栖大会将于9月24-26日举行,官网免费预约畅享票,审核后短信通知,持证件入场
1767 12
|
19天前
|
人工智能 运维 安全
|
2天前
|
资源调度
除了nrm-pm,还有哪些工具可以管理多个包管理器的源?
除了nrm-pm,还有哪些工具可以管理多个包管理器的源?
230 127
|
10天前
|
弹性计算 Kubernetes jenkins
如何在 ECS/EKS 集群中有效使用 Jenkins
本文探讨了如何将 Jenkins 与 AWS ECS 和 EKS 集群集成,以构建高效、灵活且具备自动扩缩容能力的 CI/CD 流水线,提升软件交付效率并优化资源成本。
362 0

热门文章

最新文章