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

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.

主站蜘蛛池模板: 温州市| 岳普湖县| 宜昌市| 寿宁县| 玛多县| 宜丰县| 咸丰县| 靖远县| 鄂伦春自治旗| 汪清县| 合阳县| 金乡县| 景泰县| 衡水市| 宜丰县| 铅山县| 临朐县| 大安市| 民权县| 海口市| 泾川县| 泸定县| 南江县| 唐山市| 吉水县| 南皮县| 普安县| 工布江达县| 泾川县| 仪征市| 洪泽县| 延边| 洛南县| 绥阳县| 进贤县| 佛坪县| 宜州市| 阳泉市| 科技| 卢氏县| 金溪县|