Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

MVVM in Windows 8 und Windows Phone 8

Ähnliche Präsentationen


Präsentation zum Thema: "MVVM in Windows 8 und Windows Phone 8"—  Präsentation transkript:

1 MVVM in Windows 8 und Windows Phone 8
Thomas Claudius Huber Trivadis AG

2 Thomas Claudius Huber Principal Consultat bei Trivadis
Trainer, Coach, Developer, Architect Spezialisiert auf XAML, WPF, UI Microsoft MVP im Bereich Client Development Autor umfassender Handbücher WPF, Windows Store Apps und Silverlight

3 Sessioninhalt MVVM - Grundlagen Portable Class Libraries Tipps & Tricks

4 MVVM-Grundlagen

5 MVVM - Grundlagen View ViewModel Model View Data Binding ViewModel
Das UI (XAML) ViewModel Model für das UI Enthält Daten & Commands Model Datenobjekte View Data Binding ViewModel Referenz Model

6 Stärken von MVVM Höhere Wartbarkeit Unterstütztung von Unit-Tests
UI und UI-Logik sind strikt getrennt Unterstütztung von Unit-Tests ViewModels und die darin enthaltene UI-Logik lassen sich testen Die View lässt sich einfach austauschen

7 Wichtige Klassen und Interfaces
ICommand Erlaubt dem UI das Ausführen von Logik im ViewModel Beim MVVM-Pattern kommt eine spezielle Implementierung zum Einsatz Oft als DelegateCommand bezeichnet INotifyPropertyChanged Definiert das PropertyChanged-Event Darüber wird das UI über Änderungen von Properties einer Klasse informiert ObservableCollection<T> für Datensammlungen Implementiert das INotifyCollectionChanged-Interface Dieses benachrichtigt das UI bei einer Änderung der Collection

8 Eine kleine MVVM-Phone-App
Demo

9 Neuerungen in .NET 4.5 CallerMemberName-Attribut wurde eingeführt Demo
Für optionale Parameter Der Compiler fügt den Namen des Aufrufers automatisch ein, wenn dieser nicht angegeben wird protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null) { var handler = PropertyChanged; if (handler != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } Demo

10 Sessioninhalt MVVM - Grundlagen Portable Class Libraries Tipps & Tricks

11 Portable Class Libraries

12 .NET Frameworks .NET Framework 4.5 Silverlight 5
.NET für Windows Phone .NET für Windows Store Apps Silverlight 5

13 Portable Class Library
Neue Projekt-Vorlage Vefügbar ab Visual Studio 2012 Referenzierbar in verschiedenen Projekten .NET, Windows Store Apps, Windows Phone, Silvelright Vereinfacht eine gemeinsame Codebasis Demo

14 Portable Class Library Feature Matrix
.NET Framework 4.5 Windows Store Windows Phone 8 Silverlight 5 Core ü LINQ IQueryable MEF Serialization WCF MVVM Dynamic Keyword ...

15 Portable Libraries und MVVM
View Das UI (XAML) ViewModel Model für das UI Enthält Daten & Commands Model Datenobjekte View Plattform -spezifisch Data Binding ViewModel Referenz Portable Class Library Model

16 ViewModel und Model in Portable Class Library migrieren
Demo

17 Portable Class Library in Windows Store App nutzen
Demo

18 Sessioninhalt MVVM - Grundlagen Portable Class Libraries Tipps & Tricks

19 Tipps & Tricks

20 Abstractions Windows Store App Windows Phone App
View View Plattform-spezifische Impl. Plattform-spezifische Impl. Portable Class Library Referenz Referenz ViewModel Model Plattform Abstraktion

21 Abstractions in Portable Library definieren und in Apps implementieren
Demo

22 Abstractions Windows Store App Windows Phone App
View View ITodoItemDataProvider-Imp. ITodoItemDataProvider-Imp Portable Class Library Referenz Referenz ViewModel Model ITodoItemDataProvider

23 Dateien als Link referenzieren
WinRT und WinPRT haben gemeinsame Basis Somit 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 arbeiten So lässt sich plattform-spezifischer Code ein-/ausschalten Jede Plattform hat sog. Conditional Compilation Symbols: Windows_Phone, NETFX_CORE (Windows Store App) Demo

24 ITodoItemDataProvider-Imp Portable Class Library ITodoItemDataProvider
Linked Files Windows Store App Windows Phone App View View Link ITodoItemDataProvider-Imp Portable Class Library Referenz Referenz ViewModel Model ITodoItemDataProvider

25 Weitere Optimierungen
Service Locator in Portable Class Library Dependency Injection Bspw. gibt es das Framework Autofac als Portable Class Library public static class ServiceLocator { public static ITodoItemDataProvider TodoItemDataProvider { get; set; } ... }

26 Sessioninhalt MVVM - Grundlagen Portable Class Libraries Tipps & Tricks

27 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 Abstraktionen Interface in Portable Class Library, Implementierung je Plattform WinRT und WinPRT über verlinkte Dateien

28 Next Session Weitere Infos zur WinPRT und Portable Class Libraries in der Session Uhr: Entwickeln von Windows Phone Unternehmens-Apps Raum: San Francisco

29 Tolle Preise am Trivadis Stand

30 www.thomasclaudiushuber.com/talks.php Slides/Samples unter:
3/28/2017 8:12 PM Slides/Samples unter: Mail: © 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. © 2010 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.


Herunterladen ppt "MVVM in Windows 8 und Windows Phone 8"

Ähnliche Präsentationen


Google-Anzeigen