Windows8 Metro开发 (02) : AppBar控件之TopAppBar
- 显示在页面顶部的TopAppBar
- 显示在页面底部的BottomAppBar
- <Page.TopAppBar>
- <AppBar x:Name="globalAppbar" Padding="10,0,10,0" Loaded="OnAppbarLoaded">
- <Grid Background="Black">
- <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Auto">
- <Button x:Name="homeAppbarButton" Style="{StaticResource GlobalPageHomeAppBarButtonStyle}" Click="OnHomeAppbarButtonClicked"></Button>
- <Button x:Name="appbarPageAppbarButton" Style="{StaticResource GlobalPageAppBarPageAppBarButtonStyle}" Click="OnAppbarPageAppbarButtonClicked"></Button>
- <Button x:Name="localDataPageAppbarButton" Style="{StaticResource GlobalPageLocalDataPageAppBarButtonStyle}" Click="OnLocalDataPageAppbarButtonClicked"></Button>
- <Button x:Name="settingPanelPageAppbarButton" Style="{StaticResource GlobalPageSettingPanelPageAppBarButtonStyle}" Click="OnSettingPanelPageAppbarButtonClicked"></Button>
- </StackPanel>
- </Grid>
- </AppBar>
- </Page.TopAppBar>
- <Setter Property="Foreground" Value="{StaticResource AppBarItemForegroundThemeBrush}"/>
- <Setter Property="VerticalAlignment" Value="Stretch"/>
- <span style="color:#ff0000;"><Setter Property="FontFamily" Value="Segoe UI Symbol"/></span>
- <Setter Property="FontWeight" Value="Normal"/>
- <span style="color:#ff0000;"><Setter Property="FontSize" Value="40"/></span>
- <Setter Property="AutomationProperties.ItemType" Value="App Bar Button"/>
其中字体必须为Segoe UI Symbol.后面会讲到原因。
- <ControlTemplate TargetType="ButtonBase">
- <Grid x:Name="RootGrid" Width="100" Height="100" Margin="10">
- <Grid x:Name="BackgroundGrid" Width="100" Height="100" Background="Purple" Opacity=".6"></Grid>
- <StackPanel VerticalAlignment="Top" Margin="0,12,0,11" >
- <Grid Width="100" Height="50" Margin="0,0,0,5" HorizontalAlignment="Center">
- <TextBlock x:Name="BackgroundGlyph" Text="" FontFamily="Segoe UI Symbol" FontSize="53.333" Margin="-4,-19,0,0" Foreground="{StaticResource AppBarItemBackgroundThemeBrush}"/>
- <ContentPresenter x:Name="Content" HorizontalAlignment="Center" Margin="-1,-1,0,0" VerticalAlignment="Center"/>
- </Grid>
- <TextBlock
- x:Name="TextLabel"
- Text="{TemplateBinding AutomationProperties.Name}"
- Foreground="{StaticResource AppBarItemForegroundThemeBrush}"
- Margin="0,0,2,0"
- FontSize="11"
- TextAlignment="Center"
- Width="88"
- MaxHeight="32"
- TextTrimming="WordEllipsis"
- HorizontalAlignment="Center"
- Style="{StaticResource BasicTextStyle}"/>
- </StackPanel>
- ...
- </Grid>
- </ControlTemplate>
- <Style x:Key="GlobalPageAppBarPageAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource GlobalPageAppBarButtonStyle}">
- <Setter Property="AutomationProperties.AutomationId" Value="GlobalPageAppBarPageAppBarButton"/>
- <Setter Property="AutomationProperties.Name" Value="AppBar示例"/>
- <Setter Property="Content" Value=""/>
- </Style>
可以看到,我们只需要引用之前的基本属性和布局,再根据Button的类型修改和添加相应的属性就可以了。
其实上面的"图片"是特殊字符,你可以在字符映射表里找到它们。Value里面的空白部分就是字符的值。
- <Grid x:Name="rootGrid">
- <Frame x:Name="globalFrame"></Frame>
- </Grid>
后面就用这个Frame来进行页面的导航。
- if (!rootFrame.Navigate(typeof(GlobalPage)))
- {
- throw new Exception("Failed to create initial page");
- }
2.加载完GlobalPage页面时,再跳到HomePage。
- NavigateToPage(typeof(HomePage), globalFrame);
这样就可以在各个页面调用TopAppBar了.
- private void OnSettingPanelPageAppbarButtonClicked(object sender, RoutedEventArgs e)
- {
- NavigateToPage(typeof(SettingPanelPage));
- }
- private void NavigateToPage(Type type)
- {
- NavigateToPage(type, null);
- }
- private void NavigateToPage(Type type,object obj)
- {
- globalFrame.Navigate(type, obj);
- globalAppbar.IsOpen = false;
- }
最后别忘记关闭AppBar.
- DisableButton = GetDisableButton(globalFrame.CurrentSourcePageType);
- private Button GetDisableButton(Type type)
- {
- Button button = null;
- if(type.Equals(typeof(HomePage)))
- {
- button = homeAppbarButton;
- }
- else if (type.Equals(typeof(AppBarPage)))
- {
- button = appbarPageAppbarButton;
- }
- else if (type.Equals(typeof(LocalDataPage)))
- {
- button = localDataPageAppbarButton;
- }
- else if (type.Equals(typeof(SettingPanelPage)))
- {
- button = settingPanelPageAppbarButton;
- }
- return button;
- }
- Grid grid = (sender as AppBar).Content as Grid;
- foreach (var element in grid.Children)
- {
- if (element is StackPanel)
- {
- StackPanel panel = element as StackPanel;
- foreach (var subElement in panel.Children)
- {
- Button button = subElement as Button;
- button.IsEnabled = true;
- }
- }
- }
- DisableButton.IsEnabled = false;
OK,完事了。
- <VisualState x:Name="PointerOver">
- <Storyboard>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGrid" Storyboard.TargetProperty="Opacity">
- <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
- </ObjectAnimationUsingKeyFrames>
- <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
- <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource AppBarItemPointerOverForegroundThemeBrush}"/>
- </ObjectAnimationUsingKeyFrames>
- </Storyboard>
- </VisualState>
- if (ApplicationView.Value == ApplicationViewState.Snapped)
- {
- globalAppbar.IsOpen = false;
- return;
- }
Windows8 Metro开发 (02) : AppBar控件之TopAppBar相关推荐
- Windows8 Metro开发 (03) : AppBar控件之BottomAppBar
BottomAppBar 在介绍BottomAppBar之前还是先上张图. 这次我们关注底部的AppBar. 上图的AppBar分为左右2个部分. 左侧是引用系统自带的AppBar按钮,右侧是自定义的 ...
- 【Win 10应用开发】SplitView控件
[Win 10应用开发]SplitView控件 原文:[Win 10应用开发]SplitView控件 SplitView控件用于呈现分隔视图,简单地说,就是把一个视图分割为两部分,Content属性所 ...
- 用友二次开发 用友控件 Js宿主脚本 调用用友T6 登录 参照 控件示例
用友二次开发 用友控件 Js宿主脚本 调用用友T6 登录 参照 控件示例 /*****************************************, code by 张朋 ' Email: ...
- 分享-WinForm界面开发之布局控件WeifenLuo.WinFormsUI.Docking的使用
分享自伍华聪的-WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用 本篇介绍Winform程序开发中的布局界面的设计,介绍如何在我的 ...
- Qt界面开发(各种控件以及图表)
Qt界面开发(各种控件以及图表) 1.Qt简洁窗体 源代码链接:点击打开链接 2.QT漂亮界面 源代码链接:点击打开链接 3.音乐播放器界面 源代码链接:点击打开链接 4.六宫格界面 源代码链接:点击 ...
- [译][Tkinter 教程02] Message 控件
已获原作者授权. 原系列地址: Python Tkinter Message 控件 Message 控件用来展示一些文字短消息. Message 和 Label 控件有些类似, 但在展示文字方面比 L ...
- firefox扩展开发(八) :控件激活
firefox扩展开发(八) :控件激活 2008-06-11 17:01 当我们用鼠标点击一个控件,或者用TAB键移动到一个控件上时,我们说这个控件被激活 了(focus),离开这个控件时,我们说这 ...
- UG/NX二次开发 选择坐标系控件 UF_UI_specify_csys
文章作者:里海 来源网站:https://blog.csdn.net/WangPaiFeiXingYuan 简介: UG/NX二次开发 选择坐标系控件 UF_UI_specify_csys 与 老函数 ...
- android include 控件详解,Android开发中include控件用法分析
本文实例讲述了Android开发中include控件用法.分享给大家供大家参考,具体如下: 我们知道,基于Android系统的应用程序的开发,界面设计是非常重要的,它关系着用户体验的好坏.一个好的界面 ...
最新文章
- GPT-3开始探索付费使用:每月700块,写得比莎士比亚还多
- php 清除之前echo_PHP入门读书笔记(三): 常量和变量
- git使用-设置项目忽略文件
- Java对异常处理或抛出之后,后面代码会不会再执行?
- zynqpl端时钟_第十二章 ZYNQ-MIZ702 PS读写PL端BRAM
- spring的事物配置
- 在Perl程序中显示进度条之多姿多彩的自写代码
- 通用滤波器设计----东南大学的
- windosw7 Hosts文件的位置
- 六一特辑丨“我的礼物我开发”这群小朋友在用新的方式对话未来
- 一览众山小的上一句是什么,怎么理解一览众山小的意思?
- HDU-2502 月之数 组合数
- 曼昆《经济学原理宏观》读书笔记
- IAR Embedded Workbench IDE 显示行号
- JavaScript如何获取css属性
- 某班的成绩出来了,现在老师要把班级的成绩打印出来,和 显示当前时间
- [转载] vim风格设置
- DiskGeniux无损分区
- vnc以及xfce安装\xrdp连接
- 全国计算机一级选择题免费,全国计算机一级考试选择题试题与详细答案
热门文章
- 【Groovy】map 集合 ( map 集合定义 | 通过 getClass 函数获取 map 集合的类型 | 代码示例 )
- 【Windows 逆向】OD 调试器工具 ( OD 调试数据时硬件断点对应的关键代码 | 删除硬件端点恢复运行 )
- 【Android 逆向】IDA 工具使用 ( 十六进制视图 Hex View-1 | 结构体视图 Structures | 枚举视图 Enums | 导入视图 Import | 导出视图 )
- 【Android 插件化】插件化技术弊端 ( 恶意插件化程序的解决方向 | 常用的插件化虚拟引擎 )
- 【FFmpeg】FFmpeg 帮助文档使用
- 【Android 进程保活】应用进程拉活 ( 账户同步拉活 | 账号添加 | 源码资源 )
- 【Android 系统开发】Android JNI 之 JNIEnv 解析
- Cocos2d-x3.0 不规则Button
- js获取浏览器宽度和高度值
- 梳理一下我理解的aop