The modern user interface is constructed from visual objects of various sorts. Depending on the operating system, these visual objects might go by different names—controls, elements, views, widgets but they are all devoted to the jobs of presentation or interaction or both. 

In Xamarin.Forms, the objects that appear on the screen are collectively called visual elements. They come in three main categories:
  page
  layout
  view 

These are not abstract concepts! The Xamarin.Forms application programming interface (API) defines classes named VisualElement, Page, Layout, and View. These classes and their descendants form the backbone of the Xamarin.Forms user interface. VisualElement is an exceptionally important class in Xamarin.Forms. A VisualElement object is anything that occupies space on the screen. 

A Xamarin.Forms application consists of one or more pages. A page usually occupies all (or at least a large area) of the screen. Some applications consist of only a single page, while others allow navigating between multiple pages. In many of the early chapters in this book, you’ll see just one type of page, called a ContentPage. 

On each page, the visual elements are organized in a parent-child hierarchy. The child of a ContentPage is generally a layout of some sort to organize the visuals. Some layouts have a single child, but many layouts have multiple children that the layout arranges within itself. These children can be other layouts or views. Different types of layouts arrange children in a stack, in a two-dimensional grid, or in a more freeform manner. In this chapter, however, our pages will contain just a single child.

The term view in Xamarin.Forms denotes familiar types of presentation and interactive objects: text, bitmaps, buttons, text-entry fields, sliders, switches, progress bars, date and time pickers, and others of your own devising. These are often called controls or widgets in other programming environments. This book refers to them as views or elements. In this chapter, you’ll encounter the Label view for displaying text. 

原文

  用户界面是由各种各样的可视化对象构成,由于操作系统不同,可视化对象通常会包含元素、视图和插件,但是他们的目的都是用于展示和交互。

  在Xamarin.Forms中,在屏幕上显示出来的对象统称为可视化元素,它们有三大类:

  • page(页面)
  • layout(布局)
  • view(视图)

  它们并不是抽象的概念,在Xamarin.Forms的API中定义了这几个类:VisualElement, Page, Layout和View。这些类以及它们的子类是Xamarin.Forms用户界面的基础。VisualElement在Xamarin.Forms中是一个非常重要的类,VisualElement对象可在屏幕上开辟一个区域。

  一个Xamarin.Forms通常包含一个或多个页面,一个Page通常会占满一个屏幕的尺寸。有些应用只包含一个Page,有多个Page的应用需要在不同Page之间提供导航功能。在这本书的前几章,都使用的是一种类型的Page,叫做ContentPage。

  在每个Page中,可视化元素被组织在一个父节点-子节点的结构中(控件树)。ContentPage的子节点通常是一类组织可视化元素的布局元素。一些布局元素只有一个子节点,而大多数布局元素可以包含多个子节点,甚至子节点就是一个布局元素。不同布局元素在安排子节点的方式上个不相同,可以是栈,可以是二维表格,或者是更自由的方式。然而,在这个章节,我们的Page页只包含一个子节点。

  在Xamarin.Forms中的View元素指的是一类用于展示和交互的对象:text(文字), bitmaps(图像), buttons(按钮), text-entry fields(文本输入), sliders(滑块), switches(开关), progress bars(进度条), date and time pickers(日期和时间选择)和自定义。在其他的开发环境中,这些内容通常被叫做控件或者插件。在这本书中称它们为视图或者元素,这一章节,你会遇到Label视图,来显示一段文本。

Using either Microsoft Visual Studio or Xamarin Studio, let’s create a new Xamarin.Forms application by using a standard template. This process creates a solution that contains up to six projects: five platform projects—for iOS, Android, the Universal Windows Platform (UWP), Windows 8.1, and Windows Phone 8.1—and a common project for the greater part of your application code. 

In Visual Studio, select the menu option File > New > Project. At the left of the New Project dialog, select Visual C# and then Cross-Platform. In the center part of the dialog you’ll see several available solution templates, including three for Xamarin.Forms:
  Blank App (Xamarin.Forms Portable)
  Blank App (Xamarin.Forms Shared)
  Class Library (Xamarin.Forms)
Now what? We definitely want to create a Blank App solution, but what kind? 

Xamarin Studio presents a similar dilemma but in a different way. To create a new Xamarin.Forms solution in Xamarin Studio, select File > New > Solution from the menu, and at the left of the New Project dialog, under Multiplatform select App, pick Forms App, and press the Next button. Toward the bottom of the next screen are a pair of radio buttons labeled Shared Code. These buttons allow you to choose one of the following options:
  Use Portable Class Library
  Use Shared Library 

The term “Portable” in this context refers to a Portable Class Library (PCL). All the common application code becomes a dynamic-link library (DLL) that is referenced by all the individual platform projects. 

The term “Shared” in this context means a Shared Asset Project (SAP) containing loose code files (and perhaps other files) that are shared among the platform projects, essentially becoming part of each platform project. 

原文

  不管你使用的是Xamarin Studio还是Visual Studio,我们通过使用标准模板来创建一个Xamarin.Forms应用程序。这个过程中,我们会创建6个项目:5个平台项目(iOS, Android,UWP, Windows 8.1, Windows Phone 8.1)和一个公共项目(应用程序代码的大部分都在这个项目中)。

  在Visual Studio中选择菜单:文件>新建>项目。然后在新建项目对话框的左侧选择:Visual C#>Cross-Platform。在对话框中间部分,可以看到这几个可以使用的解决方案模板,有3个是针对Xamarin.Forms的。

  • Blank App (Xamarin.Forms Portable) :可移植的Xamarin.Forms解决方案
  • Blank App (Xamarin.Forms Shared):可共享的Xamarin.Forms解决方案
  • Class Library (Xamarin.Forms):Xamarin.Forms类库项目

  如果我们现在要创建一个空白解决方案,要如何选择呢?

For now, pick the first one: Blank App (Xamarin.Forms Portable) in Visual Studio or Use Portable Class Library in Xamarin Studio. Give the project a name—for example, Hello—and select a disk loca-tion for it in that dialog (in Visual Studio) or in the dialog that appears after pressing the Next button again in Xamarin Studio. 

If you’re running Visual Studio, six projects are created: one common project (the PCL project) and five application projects. For a solution named Hello, these are:
  A Portable Class Library project named Hello that is referenced by all five application projects;
  An application project for Android, named Hello.Droid;
  An application project for iOS, named Hello.iOS;
  An application project for the Universal Windows Platform of Windows 10 and Windows Mobile 10, named Hello.UWP;
  An application project for Windows 8.1, named Hello.Windows; and
  An application project for Windows Phone 8.1, named Hello.WinPhone.
If you’re running Xamarin Studio on the Mac, the Windows and Windows Phone projects are not created. 

原文

  首先在Visual Studio的创建项目对话框中选择:空白应用(可移植Xamarin.Forms),取一个项目名称Hello,然后选择项目位置,然后确定。

  解决方案创建结束后,可以看到一共创建了6个项目,一个公共项目(PLC)和5个应用程序项目,如果是使用Xamarin Studio在Mac上创建解决方案,不会包括最后两个项目:

  • 可移植的类库项目,名称为Hello,被其他几个项目引用。
  • 一个安卓应用程序项目,Hello.Droid
  • 一个iOS应用程序项目,Hello.iOS
  • 一个UWP应用程序项目,Hello.UWP
  • 一个Windows 8.1应用程序项目,Hello.Windows
  • 一个Windows Phone 8.1应用程序项目,Hello.WinPhone

移除iOS项目(目前先不研究这个),然后编译各个项目,发现Droid项目编译出现下面错误:

根据错误中给出的地址下载文件android_m2repository,然后将文件名重新命名为96659D653BDE0FAEDB818170891F2BB0.zip,然后到错误提示中的目录C:\Users\freesaber\AppData\Local\Xamarin\zips中替换目录中的文件。然后再次生成,这个时候,错误就只剩下3个。

这个时候,我们要删除C:\Users\freesaber\AppData\Local\Xamarin目录下面的v4目录,再重新生成解决方案即可:

When you create a new Xamarin.Forms solution, the Xamarin.Forms libraries (and various support libraries) are automatically downloaded from the NuGet package manager. Visual Studio and Xamarin Studio store these libraries in a directory named packages in the solution directory. However, the par-ticular version of the Xamarin.Forms library that is downloaded is specified within the solution tem-plate, and a newer version might be available. 

In Visual Studio, in the Solution Explorer at the far right of the screen, right-click the solution name and select Manage NuGet Packages for Solution. The dialog that appears contains selectable items at the upper left that let you see what NuGet packages are installed in the solution and let you install others. You can also select the Update item to update the Xamarin.Forms library.   

In Xamarin.Studio, you can select the tool icon to the right of the solution name in the Solution list and select Update NuGet Packages.   

Before continuing, check to be sure that the project configurations are okay. In Visual Studio, select the Build > Configuration Manager menu item. In the Configuration Manager dialog, you’ll see the PCL project and the five application projects. Make sure the Build box is checked for all the projects and the Deploy box is checked for all the application projects (unless the box is grayed out). Take note of the Platform column: If the Hello project is listed, it should be flagged as Any CPU. The Hello.Droid project should also be flagged as Any CPU. (For those two project types, Any CPU is the only option.) For the Hello.iOS project, choose either iPhone or iPhoneSimulator depending on how you’ll be testing the program.

原文

  当你创建一个新的Xamarin.Forms解决方案的时候,项目所需的各种类库会自动的NuGet包管理器进行下载。在Visual Studio或者Xamarin Studio中,这些库文件会存放在一个解决方案目录下的packages的文件夹中。可以自己通过报管理器获取一个最新的更新。在VisualStudio的解决方案资源管理器的右侧,右击解决方案,选择NuGet包管理器,通过弹出的选项卡,你可以搜索安装其他的库,或者对现有库进行更新。

For the Hello.UWP project, the project configuration must be x86 for deploying to the Windows desktop or an on-screen emulator, and ARM for deploying to a phone. 

For the Hello.WinPhone project, you can select x86 if you’ll be using an on-screen emulator, ARM if you’ll be deploying to a real phone, or Any CPU for deploying to either. Regardless of your choice, Visual Studio generates the same code. 

If a project doesn’t seem to be compiling or deploying in Visual Studio, recheck the settings in the Configuration Manager dialog. Sometimes a different configuration becomes active and might not include the PCL project. In Xamarin Studio on the Mac, you can switch between deploying to the iPhone and iPhone simulator through the Project > Active Configuration menu item. 

In Visual Studio, you’ll probably want to display the iOS and Android toolbars. These toolbars let you choose among emulators and devices and allow you to manage the emulators. From the main menu, make sure the View > Toolbars > iOS and View > Toolbars > Android items are checked. 

In Visual Studio, you’ll probably want to display the iOS and Android toolbars. These toolbars let you choose among emulators and devices and allow you to manage the emulators. From the main menu, make sure the View > Toolbars > iOS and View > Toolbars > Android items are checked. 

In the Solution Explorer of Visual Studio, right-click any of the five application projects and select the Set As StartUp Project item from the menu. You can then select to deploy to either an emulator or a real device. To build and run the program, select the menu item Debug > Start Debugging. 

In the Solution list in Xamarin Studio, click the little tool icon that appears to the right of a selected project and select Set As Startup Project from the menu. You can then pick Run > Start Debugging from the main menu. 

If all goes well, the skeleton application created by the template will run and you’ll see a short message: 

原文

As you can see, these platforms have different color schemes. The iOS and Windows 10 Mobile screens display dark text on a light background, while the Android device displays light text on a black background. By default, the Windows 8.1 and Windows Phone 8.1 platforms are like Android in displaying light text on a black background.  

By default, all the platforms are enabled for orientation changes. Turn the phone sideways, and you’ll see the text adjust to the new center. 

The app is not only run on the device or emulator but deployed. It appears with the other apps on the phone or emulator and can be run from there. If you don’t like the application icon or how the app name displays, you can change that in the individual platform projects. 

原文

显示hello的更多相关文章

  1. win10 环境 gitbash 显示中文乱码问题处理

    gitbash 是 windows 环境下非常好用的命令行终端,可以模拟一下linux下的命令如ls / mkdir 等等,如果使用过程中遇到中文显示不完整或乱码的情况,多半是因为编码问题导致的,修改 ...

  2. 关于textview显示特殊符号居中的问题

    话说这是2017年的第一篇博客,也是一篇技术博客.先从简单的一篇解决问题开始吧,千里之行,始于足下! ------------------------------------------------- ...

  3. IE的F12开发人员工具不显示问题

    按下F12之后,开发人员工具在桌面上看不到,但是任务栏里有显示.将鼠标放在任务栏的开发人员工具上,出现一片透明的区域,选中之后却出不来.将鼠标移动到开发人员工具的缩略图上,右键-最大化,工具就全屏出现 ...

  4. input[tyle="file"]样式修改及上传文件名显示

    默认的上传样式我们总觉得不太好看,根据需求总想改成和上下结构统一的风格…… 实现方法和思路: 1.在input元素外加a超链接标签 2.给a标签设置按钮样式 3.设置input[type='file' ...

  5. css实现单行,多行文本溢出显示省略号……

    1.单行文本溢出显示省略号我们可以直接用text-overflow: ellipsis 实现方法: <style> .div_text{width: 300px; padding:10px ...

  6. MVC Core 网站开发(Ninesky) 2.1、栏目的前台显示(补充)

    在2.1.栏目的前台显示中因右键没有添加视图把微软给鄙视了一下,后来有仔细研究了一下发现应该鄙视自己,其实这个功能是有的,是自己没搞清楚乱吐糟. 其实只要在NuGet中安装两个包(Microsoft. ...

  7. MVC Core 网站开发(Ninesky) 2.1、栏目的前台显示

    上次创建了栏目模型,这次主要做栏目的前台显示.涉及到数据存储层.业务逻辑层和Web层.用到了迁移,更新数据库和注入的一些内容. 一.添加数据存储层 1.添加Ninesky.DataLibrary(与上 ...

  8. 让kindeditor显示高亮代码

    kindeditor4.x代码高亮功能默认使用的是prettify插件,prettify是Google提供的一款源代码语法高亮着色器,它提供一种简单的形式来着色HTML页面上的程序代码,实现方式如下: ...

  9. ASP.NET Core应用针对静态文件请求的处理[5]: DefaultFilesMiddleware中间件如何显示默认页面

    DefaultFilesMiddleware中间件的目的在于将目标目录下的默认文件作为响应内容.我们知道,如果直接请求的就是这个默认文件,那么前面介绍的StaticFileMiddleware中间件会 ...

  10. Nested Loops join时显示no join predicate原因分析以及解决办法

    本文出处:http://www.cnblogs.com/wy123/p/6238844.html 最近遇到一个存储过程在某些特殊的情况下,效率极其低效, 至于底下到什么程度我现在都没有一个确切的数据, ...

随机推荐

  1. Octopus系列之数据上传格式要求说明

    各个数据列要求 价格列:字符串类型[美元价格] 产品名字:可以支持"/"等字符 分类名字:去空格处理 不得包含"&"符号 主图:一定要有主图列 不为空 ...

  2. jquery mobile 教程

    简介:jQuery Mobile框架可以轻松的帮助我们实现非常好看的.可跨设备的Web应用程序.我们将后续的介绍中向大家介绍大量的代码及实例. jQuery一直以来都是非常流行的富客户端及Web应用程 ...

  3. .gitignore

    # Xcode # build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *. ...

  4. sql2008 无法附加数据库

    sql2008 因为数据库正在使用,所以无法获得对数据库的独占访问权---还原或删除数据库的解决方法 数据库还原出现 3154错误 --主备份 --RESTORE DATABASE [NET_CN] ...

  5. 5、android ConnectivityManager获取网络状态

    ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ...

  6. fifo read

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types. ...

  7. 64位Win7系统下vs2010调试无法连接oracle

    64位win7系统的Program Files (x86)路径中有括号,oracle不认识这样的路径,所以就出现不能连接数据库的问题.所以我们可以将vs2010的内部调试web服务器WebDev.We ...

  8. python3读取chrome浏览器cookies

    好几年前我在做一些自动化的脚本时,脑子里也闪过这样的想法:能不能直接把浏览器的cookies取出来用呢? 直到昨天看到代码<python模拟发送动弹>,想起来当年我也曾经有类似的想法没能完 ...

  9. 系统不支持curl

    解决安装pinphp时出现的“系统不支持curl!”   今天在本机安装phppin开源程序时,提示“系统不支持curl!”错误. 由于我本机是UBUNTU系统,所以直接通过apt-get进行安装. ...

  10. codeforces 666A (DP)

    题目链接:http://codeforces.com/problemset/problem/666/A 思路:dp[i][0]表示第a[i-1]~a[i]组成的字符串是否可行,dp[i][1]表示第a ...