2015元旦第一弹——WP8.1应用程序栏(C#后台代码编写)
//第一次写博文,以后还请各位道友互相关照哈。废话不多说,直接进入正题。
相信大家对于如何在XAML添加应用程序栏应该很清楚,不清楚的话,可以打开新建个Pviot应用 就有系统自带的菜单栏。 本文主要讲的是如何在C#后台进行动态添加应用程序栏以及菜单栏最小化。
首先新建一个空白应用,然后在Gird下键入以下代码:
<Pivot Name="pivot" SelectionChanged="Pivot_SelectChanged">
<PivotItem Header="First"> </PivotItem> <PivotItem Header="Second"> </PivotItem> <PivotItem Header="Third"> </PivotItem>
</Pivot>
然后在MainPage.xaml.cs定义3个菜单:
CommandBar refresh;
CommandBar add;
CommandBar min;
之后,我们定一个方法PrepareAppBars()来实现应用程序栏,这个方法要在OnNavigatedTo()或者构造函数内或者页面加载内实现,这里我选择在OnNavigatedTo()内实现:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
PrepareAppBars();
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
private void PrepareAppBars()
{ //Pivot第一个页面菜单栏
refresh = new CommandBar();
refresh.IsOpen = true;
AppBarButton RefreshBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/refresh.png") } };
RefreshBtn.Label = "刷新";
RefreshBtn.Click += RefreshBtn_Click;
RefreshBtn.IsEnabled = true; // 相似的第二个菜单
AppBarButton SecondBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/add.png") } };
SecondBtn.Label = "添加";
SecondBtn.Click += SecondBtn_Click;
SecondBtn.IsEnabled = true; AppBarButton secondCommand = new AppBarButton();
secondCommand.Label = "菜单一";
secondCommand.Click += secondCommand_Click; AppBarButton secondCommand2 = new AppBarButton();
secondCommand2.Label = "菜单二";
secondCommand2.Click += secondCommand2_Click;
refresh.SecondaryCommands.Add(secondCommand);
refresh.SecondaryCommands.Add(secondCommand2); refresh.PrimaryCommands.Add(RefreshBtn);
refresh.PrimaryCommands.Add(SecondBtn); //Pivot第二个页面菜单栏
add = new CommandBar();
add.IsOpen = true; AppBarButton Pivot_SecondAppBar = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/add.png") } };
Pivot_SecondAppBar.Label = "添加";
Pivot_SecondAppBar.Click += Pivot_SecondAppBar_Click;
SecondBtn.IsEnabled = true;
add.PrimaryCommands.Add(Pivot_SecondAppBar); //Pivot第三个页面菜单栏最小化
min = new CommandBar();
AppBarButton thirdCommand = new AppBarButton();
thirdCommand.Label = "菜单三";
thirdCommand.Click += thirdCommand_Click;
min.SecondaryCommands.Add(thirdCommand); min.ClosedDisplayMode = AppBarClosedDisplayMode.Minimal; }
接着,我们定义 应用程序栏的所有单机事件:
void thirdCommand_Click(object sender, RoutedEventArgs e)
{
MessageDialog msg = new MessageDialog("菜单三");
msg.ShowAsync();
} void Pivot_SecondAppBar_Click(object sender, RoutedEventArgs e)
{
MessageDialog msg = new MessageDialog("Pivot第二个页面添加");
msg.ShowAsync();
} void SecondBtn_Click(object sender, RoutedEventArgs e)
{
MessageDialog msg = new MessageDialog("添加");
msg.ShowAsync();
} void secondCommand2_Click(object sender, RoutedEventArgs e)
{
MessageDialog msg = new MessageDialog("菜单二");
msg.ShowAsync();
} void secondCommand_Click(object sender, RoutedEventArgs e)
{
MessageDialog msg = new MessageDialog("菜单一");
msg.ShowAsync();
} void RefreshBtn_Click(object sender, RoutedEventArgs e)
{
MessageDialog msg = new MessageDialog("刷新");
msg.ShowAsync();
}
做完这些之后呢,我们就可以在Pivot_SelectChanged页面选择的时候加载指定的应用程序栏了:
private void Pivot_SelectChanged(object sender, SelectionChangedEventArgs e)
{
switch (pivot.SelectedIndex)
{
case 0:
BottomAppBar = refresh;
break;
case 1:
BottomAppBar = add;
break;
case 2:
BottomAppBar = min;
break;
}
}
2015元旦第一弹——WP8.1应用程序栏(C#后台代码编写)的更多相关文章
- JVM第一弹
JVM第一弹 基本概念 JVM是可运行java代码的假想计算机,包括一套字节码指令集,一组寄存器,一个栈,一个垃圾回收.堆和一个存储方法域.JVM是运行在操作系统之上的,它与硬件没有直接的交互. 运行 ...
- 微信小程序登录JAVA后台
代码地址如下:http://www.demodashi.com/demo/12736.html 登录流程时序登录流程时序 具体的登录说明查看 小程序官方API 项目的结构图: springboot项目 ...
- Java基础-程序流程控制第一弹(分支结构/选择结构)
Java基础-程序流程控制第一弹(分支结构/选择结构) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.if语句 1>.if语句的第一种格式 if(条件表达式){ 语句体: ...
- 我的长大app开发教程第一弹:Fragment布局
在接下来的一段时间里我会发布一个相对连续的Android教程,这个教程会讲述我是如何从零开始开发“我的长大”这个Android应用. 在开始之前,我先来介绍一下“我的长大”:这是一个校园社交app,准 ...
- typecho流程原理和插件机制浅析(第一弹)
typecho流程原理和插件机制浅析(第一弹) 兜兜 393 2014年03月28日 发布 推荐 5 推荐 收藏 24 收藏,3.5k 浏览 虽然新版本0.9在多次跳票后终于发布了,在漫长的等待里始终 ...
- 《ArcGIS Engine+C#实例开发教程》第一讲桌面GIS应用程序框架的建立
原文:<ArcGIS Engine+C#实例开发教程>第一讲桌面GIS应用程序框架的建立 摘要:本讲主要是使用MapControl.PageLayoutControl.ToolbarCon ...
- Hadoop基础-MapReduce的工作原理第一弹
Hadoop基础-MapReduce的工作原理第一弹 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在本篇博客中,我们将深入学习Hadoop中的MapReduce工作机制,这些知识 ...
- Spring Boot 第一弹,问候一下世界!!!
持续原创输出,点击上方蓝字关注我吧 目录 前言 什么是Spring Boot? 如何搭建一个Spring Boot项目? 第一个程序 Hello World 依赖解读 什么是配置文件? 什么是启动类? ...
- 2015元旦来个炫的html5特效
效果网址:http://keleyi.com/keleyi/phtml/html5/5.htm 代码: <!DOCTYPE html> <html xmlns="http: ...
随机推荐
- erlang判断模块导出函数问题
erlang本身提供一个接口,可以用来检查模块是否有导出函数,这个接口是erlang:function_exported/3,但是很多时候这个接口无法正常使用. 下面重现一下这个问题: 1> e ...
- 使用Opencv中均值漂移meanShift跟踪移动目标
Mean Shift均值漂移算法是无参密度估计理论的一种,无参密度估计不需要事先知道对象的任何先验知识,完全依靠训练数据进行估计,并且可以用于任意形状的密度估计,在某一连续点处的密度函数值可由该点邻域 ...
- drawText文字绘制知识
drawText(String text, float x, float y, Paint paint) x,y是基于文字基本线的,而不是android坐标系的左上角. 使用staticLayout进 ...
- hadoop 3.x 回收站
使用回收站最主要是为了给误删文件的你留条后路 打开core-site.xml添加以下配置 <!--回收站保存文件时间--> <property> <name>fs. ...
- VS2017十五项新功能体验
Visual Studio 2017十五项新功能体验 Visual Studio 2017正式已经于2017.3.7号正式发布,选在这一天发布也是为了纪念Visual Studio 二十周年.MVP ...
- windows 下 TensorFlow(GPU 版)的安装
windows 10 64bit下安装Tensorflow+Keras+VS2015+CUDA8.0 GPU加速 0. 环境 OS:Windows 10,64 bit: 显卡:NVIDIA GeFor ...
- VS2015如何自定义类模板、我的模板——原来这么简单!
在前一段时间忽然想给自己电脑上的vs新建类的时候添加一个自定义个注释,但是在网上搜了很久都是说vs2012之类的方法系统也都是win7.XP之类的独独没有win8的.故此自己不断的尝试修改发现方法如下 ...
- c语言学习笔记(13)——链表
链表 算法: 1.通俗定义: 解题的方法和步骤 2.狭义定义: 对存储数据的操作 3.广义定义: 广义的算法也叫泛型 无论数据是如何存储的,对数据的操作都是一样的 我们至少可以通过两种结构来存储数据 ...
- 中国新超算彻底告别进口CPU 国产芯片已可与国外抗衡
日前,飞腾已经完成FT-2000plus服务器CPU的研制工作,飞腾公司的合作伙伴正在积极研发相应的整机产品.FT-2000plus这款芯片是以FT2000为基础的改进版本,虽然在单核性能上和Inte ...
- ASP.NET Core 用户注册 - ASP.NET Core 基础教程 - 简单教程,简单编程
原文:ASP.NET Core 用户注册 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 用户注册 上一章节我们终于迁移完了 Identity 的数据,也创建 ...