xaml development with xamarin - jesse liberty | falafelcon 2014

46
XAML With Xamarin There Is Life A,er Death Jesse Liberty Master Consultant Falafel So5ware [email protected] @jesseliberty

Upload: falafelsoftware

Post on 18-Dec-2014

298 views

Category:

Software


2 download

DESCRIPTION

Mobile is the fastest growing area in software development, and Xamarin makes it possible to build native iOS, Android and Windows 8 applications using a single code base written in C#. Until recently, this meant approximately 90% code reuse. Now, Xamarin has introduced Forms, which increase code reuse to 95-99% and which are built using C# and XAML - a version of the mark up language used in Silverlight, WPF, Windows 8 and Windows Phone. This session will explore how you can create beautiful cross-platform business applications with native controls, using XAML, C# and Xamarin.Forms.

TRANSCRIPT

Page 1: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

XAML  With  Xamarin   There  Is  Life  A,er  Death  

Jesse  Liberty  Master  Consultant  Falafel  So5ware  

[email protected]  @jesseliberty  

Page 2: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

What  We  Will  Cover

• Xamarin  Forms  and  XAML  • Data  and  Data  Binding  • MVVM  

Page 3: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Am  I  In  The  Right  Presenta:on?

•  I  assume…  •  LiEle  or  no  Xamarin  Forms  experience  •  Comfortable  with  C#  •  Familiar  with  XAML  •  Interested  in  Databinding  •  Interested  in  MVVM  

Page 4: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Q&A  at  the  end    

Page 5: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

This  is  not  your  mama's  Xamarin!

• Xamarin  Forms  are  a  whole  new  thing  • Xamarin  Forms  are  the  future!*  •  For  now,  limited  but  extremely  powerful  • A  natural  migraMon  for  XAML  programmers    *  Personal  Opinion  

Page 6: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

What  Is  Xamarin?

• Xamarin  is  a  framework  that  allows  you  to  create  naMve  iOS,  Android,  Windows  Phone  and  Mac  applicaMons  in  C#.  

Page 7: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

What  Is  Xamarin  Forms?

• Create  naMve  iOS,  Android,  WP    applicaMons  (UX)  with  shared  code    • XAML  and/or  C#  

Page 8: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

What  Is  Xamarin  Studio?

• An  Integrated  Development  Environment  (IDE)  •  Similar  to  Visual  Studio  • Runs  on  Mac                  and  Windows  

Page 9: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Your  Development  Environment • OpMon  1:  Mac  only  –  Develop  iOS  and  Android  in  Xamarin  Studio  • OpMon  2:  Parallels  on  Mac,  Business  license.    Develop  iOS,  Android  and  Windows  Phone  in  Visual  Studio  • OpMon  3:  Windows  only  –  Develop  Android  and  Windows  Phone  in  Visual  Studio  or  Xamarin  Studio  

Page 10: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

XAML

• Anything  you  can  do  in  XAML  you  can  do  in  C#.      • But  don't.  

Page 11: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

XAML  and  MVVM

•  You  can  do  XAML  without  MVVM  • But  don't.  

Page 12: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

MVVM  From  The  Start

• Model:  Your  data  • View:  Your  presentaMon  (UI)  • View-­‐Model:  The  glue  •  The  logic  goes  in  the  VM  

Page 13: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Why  MVVM?

•  Proven  paEern  (WPF,  Silverlight,  etc.)  •  Especially  lends  itself  to  Xamarin  Forms  

•  Data  binding  •  XAML  

•  SeparaMon  of  concerns  •  Easier  to  maintain    •  Easier  to  test  

Page 14: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

C#  &&    XAML

• XAML  is  great  because  •  DeclaraMve  •  Machine-­‐readable  (designer?)  

Page 15: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Data  Binding

• Rather  than  copying  data  to  and  from  the  user  interface,  we  bind!  • Bind  from  any  object  to  any  widget  

Data  Source   Control  Data  Binding  

Page 16: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Element  Binding

•  You  can  even  bind  from  one  control  to  another  •  Example:  slider  to  label  

Label  Data  Binding  Slider  

Page 17: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Events

• Assign  event  handlers  • Handle  in  code-­‐behind    • No  support  yet  for  binding  events  •  Though  there  are  libraries  

Page 18: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

• CreaMng  your  first  forms  applicaMon  •  3  Projects  •  PCL  •  iOS  •  Android  

Demo  1  –  New  SoluMon  

Page 19: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

What  we're  going  to  build

•  Evaluator  is  a  mobile  applicaMon    • Helps  you  compare  items  such  as  dishwashers  •  You  can  add  criteria  you  care  about  •  You  set  how  important  each  is  

Page 20: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014
Page 21: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014
Page 22: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014
Page 23: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

•  First  MVVM  Xamarin  Forms  ApplicaMon  •  Goal:  create  a  page  that  lists  3  items  and  their  locaMon  

• Demo  2  

Page 24: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Being  No:fied

• How  do  we  update  the  UI  if  the  data  changes?  •  Implement  interface  INoMfyPropertyChanged  • Put  our  items  in  an  ObservableCollecMon  •  Sound  familiar?  

Page 25: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

• Adding  noMficaMon  • Demo  3  

Page 26: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Views  and  More

• Pages  •  Layouts  • Views  • Cells  

Page 27: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Key  Layouts  We’ll  Work  With

•  StackLayout  • GridLayout  

Page 28: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Key  Views  We’ll  Work  With

•  Label  (display  text)  •  Entry  (gather  text)  •  ListView  

Page 29: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Adding  Views  and  Data

• We  want  to  add  Criteria  for  each  item  •  Each  criterion  has  a  name,  a  descripMon,  an  importance  raMng  and  a  raMng  

•  Example:  •  Quiet  •  Higher  values  =  quieter  •  Importance  =  5  •  RaMng  =    

Page 30: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Two  New  Views

• Details  page  displays  the  criteria  for  a  selected  item  • AddCriterion  allows  you  to  add  new  criteria  for  all  items  

Page 31: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Naviga:on

• How  do  we  go  from  one  page  to  another?  • How  do  we  pass  informaMon  from  one  page  to  another?  

Page 32: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

• Criteria  • Details  Page  • Demo  4  

Page 33: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

•  Fixing  the  integers  •  Forms  provide  strings  •  Storing  numbers  as  strings  is  undesirable  •  SoluMon:  IValueConverter  

• Demo  5  

Page 34: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

• Move  the  “Add  criterion”  buEon  to  the  details  page  • Add  “Add  Item”  to  Items  page  •  Create  AddItemPage  

• Demo  6  

Page 35: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Tabbed  Pages • As  always,  write  to  the  abstracMon  •  Displays  appropriate  to  the  plamorm  

•  In  the  MainPage.xaml:  

       <TabbedPage.Children>                  <local:ItemsPage  />                  <local:HelpPage  />                  <local:LicensePage  />          </TabbedPage.Children>    

Remember  to  create  namespace  

Declare  your  tabbed  pages  

Page 36: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

•  Create  a  new  MainPage  •  Add  tabbed  Pages  

•  1st  tab  =  Items  •  2nd  tab  =  Help  •  3rd  tab  =  License  

•  Remember:  Page  type  is  TabbedPage  •  Demo  7  

Page 37: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

• Adding  to  toolbar      • Drop/Seed  DB  • Demo  8  

Page 38: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Images

•  From  •  A  file,  A  Uri,  A  Resource  

• Aspect  •  Fill,  AspectFill,  AspectFit  

• hEp://jliberty.me/dishwasherjpg  

Page 39: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Maps

• Using  Map  control  •  Sepng  locaMon  •  Sepng  MapType  

Page 40: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

• Adding  a  map  • Demo  9  

Page 41: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Custom  Rendering

• Remember  that  forms  render  naMvely  •  This  is  done  with  “Renderers”  •  You  can  write  Custom  Renderers  

Page 42: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Demo

• Custom  Rendering  • Demo  10  

Page 43: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Add  icons

•  Evaluate  

Page 44: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014
Page 45: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Ques:ons?

Page 46: XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014

Contact  Me

•  Jesse  Liberty  •  Falafel  So5ware  •  [email protected]    • @jesseliberty