Gemeinsame View-Models
mit XAML Technologien
Christian Nagel
https://csharp.christiannagel.com
Topics
Client Technologies
Dependency Injection &
Hosting DI Container (3.0)
View-Models
Christian Nagel
• Training
• Coaching
• Consulting
• Development
• Microsoft MVP
• www.cninnovation.com
• csharp.christiannagel.com
XAML Technologies
WPF
• Started with .NET Framework 3.0
• Mature
• Ported to .NET Core 3.0
• Use Analyze Project Portability with existing
applications
• Supports older versions of Windows
• Modern controls (UWP) via XAML islands
• Windows only
Demo
WPF with .NET Core
Analyze Project Portability
Universal
Windows
Platform
• XAML similar to WPF but with small differences
• Modern controls and layouts
• Windows Runtime APIs
• Native Compilation
• Compiled Binding
• Windows 10 only
• WinUI
• UWP is used to build Windows 10 user
interfaces
Demo
Windows Template Studio
Inventory App
Xamarin.Forms
• XAML is different
• Android
• Java - .NET Interop
• iOS
• Native
• UWP
• limited (e.g. new Shell)
Demo
Xamarin.Forms
Avalonia UI
• Windows, Linux, OSX
• Experimental for Android, iOS
• Renderer to OpenGL, X11
• http://avaloniaui.net/
• https://github.com/AvaloniaUI
Demo
dotnet snow
Platform Uno
• WebAssembly or Xamarin Native Stack
• XAML-Style UWP
• https://platform.uno/
• https://github.com/unoplatform
Demo
https://calculator.platform.uno
Dependency Injection
Dependency Injection
Overview
• Hollywood Principle
• Don't call us, we call you!
• Decoupling
• Code becomes easier
• Unit testing made possible
Dependency
Injection &
View-Models
• Einfachere View-Models
• Services unabhängig von View-Models
• Services über DI injecten
• Unabhängigkeit von Plattform-Features
• Dependency Injection Container erleichtern
Dependency Management
.NET Core 3
Host Class
• WebHost class replaced by Host class
• Services, configuration, and logging in one place
• Used by Worker processes, Windows Services,
Linux daemons
• Can be used with client applications as well
Demo
Host Class
Shared
Sources
• UI Technologies
• WPF
• UWP
• Xamarin
• Uno Platform
• Common Services in .NET Standard Libraries
• Common View-Models in .NET Standard
Libraries
• Platform Specific Services in technology specific
libraries/apps
MVVM
MVVM Pattern
View
View-Model
Model
Views
• XAML
• Wenig Code-Behind
• User Controls
• Styles in Resource
Dictionaries
Binding
• Binding mit Listen und Elementen
• Binding zu Properties & Commands
• Wohin mit dem DataContext?
• Pages / User Controls
• Data Context wird an User Controls weitergereicht
Models
• INotifyPropertyChanged
• Benachrichtigung bei
Änderungen
Commands
• ICommand Interface
• Commands to Delegates
• DelegateCommand
View-Models
• Basisklassen für gemeinsame Features
• Progress-Information
• Error-Handling
• Master/Detail
• Keine UI Typen im View-Model
• Properties und Commands für das View
Demo
Views, Binding, View-Models, Services,
Platform specific services
View-Models
für Items
• Items in Listen brauchen oft Commands
• View-Models können in Listen verwendet
werden
Communication
zwischen View-
Models/Views
• Lose Kopplung
• View-Models unabhängig von anderen View-
Models halten
• Singleton/Scoped service mit gemeinsamen
State
• Event Aggregator / Messenger
Applikations-
Architektur
• .NET Standard Library
• MVVM Pattern
• Binding
• Commands
• Dependency Injection
• Event Aggregation
Questions?
For action
• Microsoft.Extensions.DependencyInjection
• View-Models in .NET Standard Libraries
• Create your base view-models
• Use any XAML technology
• https://csharp.christiannagel.com
• https://github.com/cninnovation
• https://github.com/ProfessionalCSharp
Thank you!

Gemeinsame View-Models mit XAML Technologien