windows phone 7基础点随手记

1. Button:

Content:可为Grid等容器,可实现复杂布局;默认为TextBlock,结合Background设置底色可以实现大部分需求。

Tag:类似SWT中控件的Data,可以实现数据随着控件走。

2.Image:

属性设置为Resource,获取stream:App.GetResourceStream(new Uri("Images/update.png")).Stream;

代码中直接加载:Image image = new Image() {Stretch = Stretch.None, Source = new BitmapImage(new Uri("Images/update.png", UriKind.Relative))};

3.Grid:

定义行列:btnGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50, GridUnitType.Auto)});

添加控件:btnGrid.Children.Add(cityTxt);

设置控件行列:Grid.SetRow(cityTxt, 0);

4.Content、Template、Style:

Style:控件的背景、前景、Margin、字体等各种属性,包括Template;

Template:控件包含的许多控件的展示模板;

Content:某些控件拥有的属性,类似Template;

5. 简单提示:

a.MessageBoxResult res = MessageBox.Show() if(res==MessageBoxResult.OK)

注意:页面OnNagTo的10s加载原则,用户10s不响应messagebox导致App退出;

解决方法:在page_loaded中显示messagebox,全景首页可在page_loaded中再加DispatcherTimer在100ms后等待全景动画完成后再显示;

using Microsoft.Xna.Framework.GamerServices;
Guide.BeginShowMessageBox(title, content, new string[] { "确定","取消" }, 0, MessageBoxIcon.Alert, asyncResult => {
int returned =Guide.EndShowMessageBox(asyncResult);
if (returned == 0){_shouldExit = 1;}else{_shouldExit = 0;} }, null);

6. Navigate:RootFrame.Navigate(),基于每个App的RootFrame;

7. 定位服务开启状态:

App启动时通过GeoWatcher.Permission == GeoPositionPermission.Granted可判断定位服务开启状态,App切换的后台多次开关定位服务后api返回结果错误,且无法获取location;诺基亚地图等都有错,微软bing正确。

原文地址:https://www.cnblogs.com/toven/p/2340402.html