添加Application Bar

用 Expression Blend很直观。

添加Application Bar:右击 Objects and Timeline 面板上的PhoneApplicationPage,选择 Add ApplicationBar。

添加ApplicationBarIconButton: 右击ApplicationBar,选择Add ApplicationBarIconButton。

添加ApplicationBarMenuItem: 右击ApplicationBar,选择Add ApplicationBarMenuItem。(下面仅以IconButton为例,MenuItem与其类似)

ApplicationBarIconButton的属性面板:

image

Name用来命名。Search栏用来搜索属性,不过ApplicationBarIconButton的属性太少,都展开在下面了。

IconUri下拉框能找到很多自带的按钮图标,…可以自定义图标文件路径。

Text是:在触摸右边…的时候,图标按钮上浮,露出在每个图标下方的介绍性文字。

若要添加事件,则选择到右上闪电所在的面板,在Click后面的文本框里双击。

image

 

逐个设置比较麻烦,因此用循环为每个菜单项的点击事件绑定方法:

using Microsoft.Phone.Shell;   使ApplicationBarMenuItem可见

foreach (ApplicationBarMenuItem menuItem in this.ApplicationBar.MenuItems)
{
       menuItem.Click += new EventHandler(ApplicationBarMenuItem_Click);
}

在ApplicationBarMenuItem_Click里把sender类型转换成ApplicationBarMenuItem取到不同的属性值。

作者的代码中用的是接口IApplicationBarMenuItem而非具体的类ApplicationBarMenuItem,原因是微软的wp team为了将来扩展更灵活,但这里我们不必在乎。

 

ApplicationBarIconButton的初始化

ApplicationBarIconButton控件只在Xaml里面有是不行的,InitializeComponent并不能初始化它Sad smile

// Assign application bar buttons to member fields, because this cannot be done by InitializeComponent:
this.sosButton = this.ApplicationBar.Buttons[0] as ApplicationBarMenuItem;
this.strobeButton = this.ApplicationBar.Buttons[1] as ApplicationBarMenuItem;

 

作者的源码里,是把所有图片放到了Images目录下。但是通过Blend去添加图片的时候,会自动创建icons目录,因此还是统一放到icons目录里好些。

 

Windows Phone的MessageBox是简化了的,只有两个按钮,且按钮文本不能自定义。若要自定义MessageBox,则需要用到Microsoft.Xna.Framework.GamerServices。详见58页。

posted on 2011-09-27 15:46  MainTao  阅读(314)  评论(0编辑  收藏  举报