官术网_书友最值得收藏!

Shared projects

We are going to delve into our first technique for sharing code between different platforms. This is what Xamarin wants us to achieve, and reuse as much code as possible. The biggest disadvantage when developing natively is two different language, and we can't reuse anything.

Let's create our first shared project:

Our shared project will be used to contain the GalleryItem model, so whatever code we include in this shared project can be accessed by both the iOS and Android projects:

In the preceding screenshot, have a look at the Solution explorer, and notice how the shared project doesn't contain anything more than .cs code sheets. Shared projects do not have any references or components, just code that is shared by all platform projects. When our native projects reference these shared projects, any libraries being referenced via using statements come from the native projects.

Now we must have the iOS and Android projects reference the shared project; right-click on the References folder and select Edit References:

Select the shared project you just created and we can now reference the GalleryItem object from both projects.

主站蜘蛛池模板: 德阳市| 兰州市| 南陵县| 西峡县| 吉林省| 西乌珠穆沁旗| 广昌县| 敦化市| 峨山| 高淳县| 东台市| 侯马市| 洛浦县| 麻江县| 凭祥市| 亳州市| 丽江市| 抚州市| 宜昌市| 湟中县| 句容市| 萨迦县| 玉环县| 昌图县| 武川县| 嫩江县| 大同县| 疏勒县| 探索| 聂拉木县| 乌兰浩特市| 元江| 柳州市| 无棣县| 静乐县| 罗甸县| 滕州市| 鄂温| 汝州市| 共和县| 灵石县|