iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 10
3
Cloud

Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例系列 第 10

Day10 – What is Xamarin.Forms?

在正式進入實例製作之前, 先前了解一下甚麼是Xamarin.Forms, 可以用下面這張圖來解釋
http://ithelp.ithome.com.tw/upload/images/20161210/20103333tJ47cagJXu.png

簡單來說, 不僅C#後端的程式可以共用, 前台的UI 也可以共用, 這樣的好處就縮短Mobile App開發時程, 因為寫一套可以跑三種平台而且是Native App而不是用Web App打包的, 如下圖
http://ithelp.ithome.com.tw/upload/images/20161210/201033339MvkghW0PQ.png

Source code如下
http://ithelp.ithome.com.tw/upload/images/20161210/20103333leMaYPxwqd.png

沒看錯就這麼簡單, 定義一個Text之後, 會對應到各平台UI, 其概念如底下圖所示
http://ithelp.ithome.com.tw/upload/images/20161210/2010333309R5h4ejiy.png

接著來看一下Xamarin.Forms專案類型如下紅框所示
http://ithelp.ithome.com.tw/upload/images/20161210/20103333q2YWSrwbS3.png

這四種又可以再區分兩種類型, 先來看一下什麼是Portable與Shared

Portable指的是PCL( Portable Class Library)
而Shared指的是 SAP (Shared Assets Project)

Portable長相如下
http://ithelp.ithome.com.tw/upload/images/20161210/20103333n496YhJeUX.png

Shared Code長相如下
http://ithelp.ithome.com.tw/upload/images/20161210/20103333Wr4B01DAgm.png

Shared是條件式編譯, 而Portable是直接在Code裡面做部署平台的判斷, 根據看到的文章或是大神建議是採Portable為居多, 在接下來的實例中會採用Portable的專案類型

接著來看一下有Xaml跟沒Xaml的專案類型, 沒有Xaml的專案, Code會如下所示即UI的Code也定義在.cs裡
http://ithelp.ithome.com.tw/upload/images/20161210/20103333vHS6kqEEI4.png

Xaml的專案, Code會如下所示, UI會定義在.xaml, 若有寫過Silverlight或WPF, 相信對這個應該不陌生
http://ithelp.ithome.com.tw/upload/images/20161210/20103333mwrSn9v7O8.png

有Xaml跟沒Xaml的專案類型, 青菜蘿蔔各有所好, 但是由於我寫WEB FORM起家的, 故選擇Xaml的專案類型會比較適合我

然後在找Xamarin Xaml相關資料發現一個很雞肋的東西如下網址, 但是卻又很需要
http://stackoverflow.com/questions/37037900/cannot-get-xamarin-xaml-intellisense-working-in-vs-2015

就是Intellisense, 當開啟Xaml專案時, 是沒有Xamarin Xaml專用的Intellisense, 若發現有此情況, 可以用下列方式解決, 在.xaml的檔案上按滑鼠右鍵, 點選Open With
http://ithelp.ithome.com.tw/upload/images/20161210/20103333C7zF61NE3t.png

將Source Code Text Editor設為預設, 接著重啟Visual Studio
http://ithelp.ithome.com.tw/upload/images/20161210/20103333uAptaQ7VE9.png

之後會看到底下紅色框內變藍色, Intellisense也出來了
http://ithelp.ithome.com.tw/upload/images/20161210/20103333TCEcQYDO7k.png

後記: Xamarin Xaml Intellisense搞得很像隱藏版功能/images/emoticon/emoticon10.gif


上一篇
Day09 - IOS實機部署測試 Part 2
下一篇
Day11 – 實例開發之業務人員行程管理系統
系列文
Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
海綿寶寶
iT邦大神 1 級 ‧ 2016-12-25 08:47:05

看到這裡
還沒請教一個基本問題
就是用Xamarin.Forms開發
最後的產出
是各平台的native source code project
還是各平台的object code
還是其他
/images/emoticon/emoticon54.gif

或者說
是產生native source code project
還是直接產生APK/IPA
/images/emoticon/emoticon41.gif

arksu iT邦新手 2 級 ‧ 2016-12-25 09:34:36 檢舉

海大, 是直接打包APK/IPA

了解了
/images/emoticon/emoticon41.gif

我要留言

立即登入留言