cross platform mobile development with visual studio and xamarin
TRANSCRIPT
Cross platform mobile developmentwith Visual Studio and Xamarin: Architecture and code reuseIbon Landa
Plain Concepts
Native Development
iOS
Objective C
Xcode
Windows Phone
C#/Visual Basic/F#
Visual Studio
Android
Java
Eclipse
IntelliJ
Using the platform native tools
Xcode ADT Visual Studio
+
+
-
✗
Build and debug iOS applications on a Windows computer using the Visual Studio IDE
Windows
Windows 7 or higher.
Visual Studio 2010 Professional or higher.
Xamarin’s plug-in for Visual Studio.
MAC
A Macintosh running OS X Lion or higher (although we recommend the latest version).
Xamarin iOS SDK.
Apple’s Xcode IDE and iOS SDK (we recommend the latest version from the App Store).
Xamarin.iOS on Windows
Xamarin.iOS on Windows
Use PCLs
Use View Models to reuse presentation code
Heavy use of dependency injectionAllows different implementations for different platforms
Improving Code Reuse in 3 easy ways
Create a single library that can be used by multiple .net frameworks
Allows access only to functionality shared by all selected frameworks
Does some nifty namespace mapping
Makes cross platform development much easier
Microsoft and 3rd party PCLs available (HttpClient, Imaging, JSON…)
Portable Class Libraries
Shared Core
Maximizing code reuse
How to display information
What information to display
Flow of interaction
Data objects
Business logic
Etc.
Model
View Model
View Device-specific
Portable codeReferences
Databinds
UI
Application Logic
Out of the box approach
View
ViewModel
Model
Model-View-ViewModel (MVVM)
Cross Platform MVVM Development Framework
Free, open source
SupportsWP7,8WPFWinRTXamarin.AndroidXamarin.iOSXamarin.Mac
AKA Mvx
MvvmCross
XAML Code
<StackPanel><TextBox Text="{Binding Hello, Mode=TwoWay}" /><TextBlock Text="{Binding Hello}" /><Button Content="Click Me" Command="{Binding MyCommand}" /><Button Content="Go Second"
Command="{Binding GoSecondCommand}"/>
</StackPanel>
public class FirstViewModel : MvxViewModel{
private string _hello = "Hello MvvmCross";public string Hello{
get { return _hello; }set { _hello = value; RaisePropertyChanged(() => Hello); }
}
public System.Windows.Input.ICommand MyCommand{
get{
return new Cirrious.MvvmCross.ViewModels.MvxCommand(DoMyCommand);}
}
private void DoMyCommand(){
Hello = Hello + " World";}
public System.Windows.Input.ICommand GoSecondCommand{
get{
return new Cirrious.MvvmCross.ViewModels.MvxCommand(DoGoSecond);}
}private void DoGoSecond(){
ShowViewModel<SecondViewModel>();}
}
MvvmCross Architecture
Convenient way to access platform functionality
Use NinjaCoder or Nuget to add plugins
Includes Accelerometer, Email, Files, Location, Messaging, Sqlite
3rd party plugins available as well.
Consume plugins using Dependency Injection or Service locator
MvvmCross Plugins
Describe functionality using an interface in .Core
Create platform specific implementation in .xxxx
Register implementation on app startupMvx.RegisterSingleton<ISettingsPersistance>(new SettingsPersistanceWPF());
Mvx.RegisterType<IGetRemoteData, RemoteDataWpf>();
Consume plugins using Dependancy Injection or Service locatorpersistance = Mvx.Resolve<ISettingsPersistance>();
Platform specific code
Architecture overview
PCLs let you use easily share code across multiple platforms
Xamarin lets you use C# on Android, iOS and Mac
MvvmCross wraps it all up to make it easyShared PCL that holds most functionality
Platform specific apps for views and dependant code
Plugins let you easily add functionality in a cross platform friendly way
Do your own platform dependant stuff using interfaces and IoC/Dependancy Injection
Summary
Thanks!