原文:c#开发移动APP-Xamarin入门扩展

  这节主要演示了如何通过添加第二个屏幕来跟踪应用程序的call历史来扩展Phoneword应用程序。最终如下:

  按如下步骤扩展Phoneword

  在Phoneword项目右键新建Content Page,命名为CallHistoryPage

  修改后CallHistoryPage.xaml如下:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:local="clr-namespace:Phoneword;assembly=Phoneword"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Phoneword.CallHistoryPage"
Title="Call History">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="20, 40, 20, 20" />
<On Platform="Android, UWP" Value="20" />
</OnPlatform>
</ContentPage.Padding>
<StackLayout>
<ListView ItemsSource="{x:Static local:App.PhoneNumbers}" />
</StackLayout>
</ContentPage>

  双击Phoneword项目的App.xaml.cs文件

  添加PhoneNumbers属性的声明,在App构造函数中初始化该属性,并将MainPage属性初始化为NavigationPage。PhoneNumbers被用于存储应用程序打的每个电话号码

using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Xaml; [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Phoneword
{
public partial class App : Application
{
public static IList<string> PhoneNumbers { get; set; } public App()
{
InitializeComponent();
PhoneNumbers = new List<string>();
MainPage = new NavigationPage(new MainPage());
}
...
}
}

  双击Phoneword项目的MainPage.xaml文件

  在StackLayout控件的末尾添加一个按钮控件,该按钮被用于导航到拨打历史页面

<StackLayout VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Orientation="Vertical"
Spacing="15">
...
<Button x:Name="callButton" Text="Call" IsEnabled="false" Clicked="OnCall" />
<Button x:Name="callHistoryButton" Text="Call History" IsEnabled="false"
Clicked="OnCallHistory" />
</StackLayout>

  打开隐藏文件MainPage.xaml.cs,添加OnCallHistory事件处理程序方法,并修改OnCall事件处理程序方法,将转换后的电话号码添加到App.PhoneNumbers集合中,并且如果dialer变量不为null时使能callHistoryButton

using System;
using Xamarin.Forms; namespace Phoneword
{
public partial class MainPage : ContentPage
{
... async void OnCall(object sender, EventArgs e)
{
...
if (dialer != null) {
App.PhoneNumbers.Add (translatedNumber);
callHistoryButton.IsEnabled = true;
dialer.Dial (translatedNumber);
}
...
} async void OnCallHistory(object sender, EventArgs e)
{
await Navigation.PushAsync (new CallHistoryPage ());
}
}
}

  下节剖析该扩展

c#开发移动APP-Xamarin入门扩展的更多相关文章

  1. c#开发移动APP-Xamarin入门扩展剖析

    原文:c#开发移动APP-Xamarin入门扩展剖析 上节将Phoneword应用程序扩展到包含第二个屏幕,该屏幕可以跟踪应用程序的拨打历史 Navigation Xamarin.Form提供了一个内 ...

  2. 如何开发Office平台上的扩展应用(又称为Office 2013 App,Office 2013 Add-Ins,Apps for Office,Office 应用)

    Office 扩展应用(Office Apps,Office 2013 AddIns,Apps for Office)开发 —— 中文文档 继 VBA 和 VSTO 之后, 微软为 Office 平台 ...

  3. 开发一个 app 有多难?

    171 个回答 默认排序​ 道衍天机 有事情的加微信1293190838找我 1,150 人赞同了该回答 ----------------------------------------------- ...

  4. 跨平台移动APP开发进阶(二)HTML5+、mui开发移动app教程

    前端开发APP,从HBuilder开始~ 序 通过 HTML5 开发移动App 时,会发现HTML5 很多能力不具备.为弥补HTML5 能力的不足,在W3C 中国的指导下成立了www.HTML5Plu ...

  5. Selenium自动化测试,接口自动化测试开发,性能测试从入门到精通

    Selenium自动化测试,接口自动化测试开发,性能测试从入门到精通Selenium接口性能自动化测试基础部分:分层自动化思想Slenium介绍Selenium1.0/2.0/3.0Slenium R ...

  6. HBuilderX 5+APP MUI 入门

    这一套东西是用来开发app的,可以用html.js什么的写app然后给你打包就能安装到手机上,也可以轻易跨端(需要使用vue,然而我还没有熟练). HBuilder:一个敲代码的软件,敲前端代码超级方 ...

  7. Flask开发系列之快速入门

    Flask开发系列之快速入门 文档 一个最小的应用 调试模式 路由 变量规则 构造 URL HTTP 方法 静态文件 模板渲染 访问请求数据 环境局部变量 请求对象 文件上传 Cookies 重定向和 ...

  8. 【转载】用Ionic开发hybrid APP

    使用phonegap开发APP的优劣在此不必细说,快速,简单,跨平台,以及随着iOS,Android本身对webview优化所带来的不错的性能,便是其独有的优势.而且私以为在目前激烈而又变化快速的移动 ...

  9. 在vs2012中用C#开发Android应用Xamarin环境搭建

    Xamarin是Mono创始人Miguel de Icaza创建的公司,旨在让开发者可以用C#编写iOS, Android, Mac应用程序,也就是跨平台移动开发. 简介 Xamarin是基于Mono ...

随机推荐

  1. 50个SQL语句

    一个项目用到的50个SQL语句 转载 说明:下面五十个语句都依照測试数据进行过測试.最好每次仅仅单独执行一个语句. 问题及描写叙述: --1.学生表 Student(Sid,Sname,Sage,Ss ...

  2. Swift3.0为视图添加旋转动画_CABasicAnimation

    Swift2.3: //创建旋转动画 let anim = CABasicAnimation(keyPath: "transform.rotation") //旋转角度 anim. ...

  3. 【源代码】Timer和TimerTask源代码剖析

    Timer是java.util包中的一个工具类,提供了定时器的功能. 我们能够构造一个Timer对象,然后调用其schedule方法在某个特定的时间或者若干延时之后去运行一个特定的任务.甚至你能够让其 ...

  4. ebook https://salttiger.com/category/notification/

    https://salttiger.com/category/notification/ 因为个人精力有限,持续搜集.整理.分享电子书已经占用我大部分业余时间,今后不再给评论区留言的朋友们找书,还希望 ...

  5. MySQL搜索:WHERE

    MySQL指定搜索条件进行搜索能够使用where条件. 在SELECT语句中.数据依据WHERE子语句中指定的条件进行过滤,WHERE子语句在表名之后给出. product表例如以下: a 查找价格等 ...

  6. [Compose] 13. Lift into a Pointed Functor with of

    We examine the of function we've seen on a few types and discover it's the Pointed interface. Instea ...

  7. php实现 求int型数据在内存中存储时1的个数(函数都可自己实现)

    php实现 求int型数据在内存中存储时1的个数(函数都可自己实现) 一.总结 一句话总结:函数我们自己都可以实现,尤其是很多基础函数,没有工具的时候自己写. 1.php进制转换函数? base_co ...

  8. Deepin下python安装uwsgi报错: Python.h:没有那个文件或目录

    解决方法是安装python-dev,这是Python的头文件和静态库包 正在读取软件包列表... 完成正在分析软件包的依赖关系树       正在读取状态信息... 完成       下列软件包是自动 ...

  9. 安装innotop

    安装方法一: 下载地址:https://github.com/innotop/innotop yum install -y perl-TermReadKey yum install -y perl-D ...

  10. DWG 对象与ArcGIS 要素的强制对应关系

    转自原文DWG 对象与ArcGIS 要素的强制对应关系 DWG 对象与ArcGIS 要素的强制对应关系如下: Feature type DWG object types   Point Point, ...