Upload
addler-schobel
View
108
Download
0
Embed Size (px)
Citation preview
| Basel
MVVM in Windows 8 und Windows Phone 8Thomas Claudius HuberTrivadis AG
Thomas Claudius Huber
Principal Consultat bei Trivadiswww.trivadis.comwww.thomasclaudiushuber.comTrainer, Coach, Developer, Architect
Spezialisiert auf XAML, WPF, UIMicrosoft MVP im Bereich Client Development
Autor umfassender HandbücherWPF, Windows Store Apps und Silverlight
Agenda
Sessioninhalt
MVVM - GrundlagenPortable Class LibrariesTipps & Tricks
| Basel
MVVM-Grundlagen
MVVM - Grundlagen
ViewDas UI (XAML)
ViewModelModel für das UIEnthält Daten & Commands
ModelDatenobjekte
Model
ViewModel
View
Data Binding
Referenz
Stärken von MVVM
Höhere WartbarkeitUI und UI-Logik sind strikt getrennt
Unterstütztung von Unit-TestsViewModels und die darin enthaltene UI-Logik lassen sich testen
Die View lässt sich einfach austauschen
Wichtige Klassen und Interfaces
ICommandErlaubt dem UI das Ausführen von Logik im ViewModelBeim MVVM-Pattern kommt eine spezielle Implementierung zum Einsatz Oft als DelegateCommand bezeichnet
INotifyPropertyChangedDefiniert das PropertyChanged-Event Darüber wird das UI über Änderungen von Properties einer Klasse informiert
ObservableCollection<T> für DatensammlungenImplementiert das INotifyCollectionChanged-Interface Dieses benachrichtigt das UI bei einer Änderung der Collection
Eine kleine MVVM-Phone-App
Demo
Neuerungen in .NET 4.5
CallerMemberName-Attribut wurde eingeführtFür optionale ParameterDer Compiler fügt den Namen des Aufrufers automatisch ein, wenn dieser nicht angegeben wirdprotected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null){ var handler = PropertyChanged; if (handler != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); }}
Demo
Agenda
Sessioninhalt
MVVM - GrundlagenPortable Class LibrariesTipps & Tricks
| Basel
Portable Class Libraries
.NET Frameworks.NET Framework 4.5
Silverlight 5.NET für WindowsStore Apps
.NET für
Windows
Phone
Portable Class Library
Neue Projekt-VorlageVefügbar ab Visual Studio 2012
Referenzierbar in verschiedenen Projekten.NET, Windows Store Apps, Windows Phone, Silvelright
Vereinfacht eine gemeinsame Codebasis
Demo
Portable Class Library Feature MatrixFeature .NET Framework
4.5Windows Store
Windows Phone 8
Silverlight 5
Core ü ü ü üLINQ ü ü ü üIQueryable ü ü ü üMEF ü ü üSerialization ü ü ü üWCF ü ü ü üMVVM ü ü ü üDynamic Keyword
ü ü ü
...
Portable Libraries und MVVM
ViewDas UI (XAML)
ViewModelModel für das UIEnthält Daten & Commands
ModelDatenobjekte
Model
ViewModel
View
Data Binding
Referenz
Plattform-spezifisch
PortableClass Library
ViewModel und Model in Portable Class Library migrieren
Demo
Portable Class Library in Windows Store App nutzen
Demo
Agenda
Sessioninhalt
MVVM - GrundlagenPortable Class LibrariesTipps & Tricks
| Basel
Tipps & Tricks
Portable Class Library
Abstractions
Model
ViewModel
Plattform Abstraktion
Windows Store App
View
Plattform-spezifische Impl.
Windows Phone App
View
Plattform-spezifische Impl.
ReferenzReferenz
Abstractions in Portable Library definieren und in Apps implementieren
Demo
Portable Class Library
Abstractions
Model
ViewModel
ITodoItemDataProvider
Windows Store App
View
ITodoItemDataProvider-Imp.
Windows Phone App
View
ITodoItemDataProvider-Imp
ReferenzReferenz
Dateien als Link referenzieren
WinRT und WinPRT haben gemeinsame BasisSomit lässt sich Code aus Windows Phone 8 in einer Windows Store App wiederverwenden
WinRT und WinPRT sind aber kein .NET!!!Somit sind die Gemeinsamkeiten in Portable Class Libraries nicht verfügbar Diese unterstützten nur .NET Schnittmengen
In verlinkten Dateien optional mit Compiler-Direktiven wie #if arbeitenSo lässt sich plattform-spezifischer Code ein-/ausschaltenJede Plattform hat sog. Conditional Compilation Symbols: Windows_Phone, NETFX_CORE (Windows Store App)
Demo
Portable Class Library
Linked Files
Model
ViewModel
ITodoItemDataProvider
Windows Store App
View
Link
Windows Phone App
View
ITodoItemDataProvider-Imp
ReferenzReferenz
Weitere Optimierungen
Service Locator in Portable Class Library
Dependency InjectionBspw. gibt es das Framework Autofac als Portable Class Library
public static class ServiceLocator{ public static ITodoItemDataProvider TodoItemDataProvider { get; set; } ...}
Agenda
Sessioninhalt
MVVM - GrundlagenPortable Class LibrariesTipps & Tricks
Fazit
ViewModels und Models lassen sich mit Portable Class Libraries in verschiedensten Projekten nutzen.NET, Windows Phone, Windows Store App und Silverlight
Plattform-spezifische Logik mit AbstraktionenInterface in Portable Class Library, Implementierung je Plattform
WinRT und WinPRT über verlinkte Dateien
Next Session
Weitere Infos zur WinPRTund Portable Class Libraries in der Session17.00 Uhr: Entwickeln von Windows Phone Unternehmens-Apps Raum: San Francisco
Tolle Preise am Trivadis Stand
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a
commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a
commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Slides/Samples unter:
www.thomasclaudiushuber.com/talks.php
Twitter: @thomasclaudiushMail: [email protected]