an introduction to windows 8 development
TRANSCRIPT
Thinking about the future with Windows 8SILVERLIGHTSHOW.NET WEBINARS SERIESGILL CLEEREN, 29th November 2011www.snowball.be - [email protected] - @gillcleeren
About myself...• Gill Cleeren• .NET Architect @Ordina (www.ordina.be) • Microsoft Regional Director• Silverlight MVP• Speaker (TechDays, TechEd, DevReach, DevDays, NDC Norway,
Telerik Usergroup tour Sweden, UK and Scotland...)• Visug user group lead (www.visug.be)• Author (Silverlight 4 Data and services cookbook, 15 MVPs book),
SilverlightShow articles– And finishing Silverlight 5 cookbook now!
• Blog: www.snowball.be• Email: [email protected] • Twitter: @gillcleeren
Warning!
I have a cold...
Luckily for you, this is not contagious over a webinar
Some practical stuff
• Ask questions through Q&A window– We’ll answer them after the session or by personal
mail• A link to the video recording will be sent to you
XAML: a 4-day Training in London, UK
• Master XAML, Silverlight, WPF, WP7 and Windows 8!
• February 20th 24th, London, UK
• Organized by CompletITand Ordina
• More info via [email protected]
www.silverlightshow.net/trainings/training_london0212.aspxBus to training
Agenda
• What did we see at BUILD?– Hello Windows 8
• What is WinRT?– How do we write Metro apps
• Leveraging tomorrow what we know today– C# and .NET in Metro-style apps– XAML for Metro-style apps
CHRISTMAS EVE IN SEPTEMBERWhat did we get at BUILD?
Before BUILD...
We had...– Desktop apps with .NET• WPF
– Web apps with .NET• ASP.NET/ASP.NET MVC• Silverlight
At BUILD, we got...
• Steven Sinofsky annoucing hardware– Including Windows 8 running on ARM
At BUILD, some got...
It’s possible to buy this device now with Windows 7, costs around $1200
Donations welcome on paypal: [email protected] ;-)
At BUILD, we got...
• Windows 8– And everyone can get it from dev.windows.com
At BUILD, we also got...
• “Metro apps”• Windows Runtime (aka WinRT)• Visual Studio Express 2011 – Only for building Metro-style apps
• .NET 4.5• Visual Studio 11 Developer Preview– That’s “The Big One”
• And more sessions than you can shake a stick at!
DEMO
Hello future aka “The demo of Windows 8”
WINDOWS RUNTIME (WINRT)Opening Windows to managed developers
The Windows Runtime is the solid, efficient foundation
for building great Metro style apps,giving you access to Windows the language
of your choice
FACT
Windows 8
Windows Kernel Services
JavaScript(Chakra)C/C++ C#, VB
Metro style Apps
Communication & Data
Application Model
Devices & Printing
Windows Runtime APIsGraphics &
Media
XAML HTML / CSS
HTMLJavaScript
CC++
C#VB
Desktop Apps
Win32 .NET SL
Internet Explorer
Devices
SensorsGeolocation Portable NFC
Communications & Data
Contracts
XML
Web
SMSNetworking
Notifications
Local & Cloud Storage
Streams
Background Transfer
User Interface
HTML5/CSS XAML DirectX Controls
Input Accessibility Printing
Data Binding
TilesSVG
Metro style application APIs
FundamentalsApplication
ServicesAuthentication Cryptography Globalization
Memory ManagementThreading/Timers
MediaVisual Effects
Playback PlayToCapture
Windows Runtime Architecture
Windows Metadata & Namespace
Language Projection
Windows Core
Windows Runtime Core
XAML Storage …Network
UI Pickers MediaControls
Metro style app
Runtime Broker
Language Support (CLR, WinJS, CRT)
Web Host (HTML, CSS, JavaScript)
Why WinRT was born...
• We had Win32 APIs for a long time• It wasn’t a good idea to just give these to
developers to build Windows 8 apps– Developers want IntelliSense, debugging...– Developers want to use the language of their
choice Microsoft doesn’t force the developer in using a certain technology or language
So WinRT is...
• A huge improvements in the developer experience for the Windows developer– IntelliSense, debugging...
• Fast and fluid (aka responsive)– Async is the new buzzword– No synchronous IO calls
• Natural and familiar– New APIs– Language of choice
• Based on apps– Apps can “communicate” through defined app-to-app contracts– Apps should keep running no matter what the OS version
DEMOHello World in WinRT in Visual Studio 2011 Express using HTML
Windows Runtime Architecture
Windows Metadata & Namespace
Language Projection
Windows Core
Windows Runtime Core
XAML Storage …Network
UI Pickers MediaControls
Metro style app
Runtime Broker
Language Support (CLR, WinJS, CRT)
Web Host (HTML, CSS, JavaScript)
All new: Windows Metadata
• We all know assembly metadata– ILDASM can open it for you– Use extensively in CLR to know what an assembly
can do for you• Windows Metadata is the same concept but
native
Windows Metadata
• Concise, complete description of the Windows Runtime
• Generated natively from C++ or C#/VB Compiler• Efficient binary format derived CLI Metadata– Same structures, different meanings
• Rich enough to allow multi-language projection generation
• Full IntelliSense on statically known information– Same experience for managed developers as we have
today
The Windows Namespace
• Windows.* Runtime objects are in a simple, unified, hierarchical namespace
• Great IntelliSense and browsing in Visual Studio
• One clear type for each function
* Top level namespaces only
The WinRT API
• Windows.ApplicationModel• Windows.Data• Windows.Devices• Windows.Foundation• Windows.Globalization• Windows.Graphics• Windows.Management• Windows.Media • Windows.Networking• Windows.Security
• Windows.Storage • Windows.System• Windows.UI[.Xaml]• Windows.Web
DEMOSame app but now using C#
Windows Runtime Architecture
Windows Metadata & Namespace
Language Projection
Windows Core
Windows Runtime Core
XAML Storage …Network
UI Pickers MediaControls
Metro style app
Runtime Broker
Language Support (CLR, WinJS, CRT)
Web Host (HTML, CSS, JavaScript)
Language Projections
• C++• .NET• JavaScript
Windows Tailored Profile
• System.Collections• System.ComponentModel• System.Diagnostics• System.Dynamic• System.Globalization• System.IO• System.Linq• System.Net• System.Numerics• System.Reflection
• System.Resources• System.Runtime• System.Security• System.ServiceModel• System.Text• System.Threading• System.Xml
What’s missing in the Windows Tailored Profile
• Enterprise Development– ASP.NET– Console– DirectoryServices– Windows Forms– WPF– WF
• Dangerous, obsolete, legacy• Removed duplicates• Removed badly designed APIs
.NET for Metro style apps
.NET for Metro style apps
.NET 4.5 Windows Phone 7
# of assemblies 15* 120 22
# of namespaces 60 400 88
# of types ~1K ~14K ~2K
# of members ~10K ~110K ~14K
* Refers to implementation assemblies, not reference assemblies.
LEVERAGING TOMORROW WHAT WE KNOW TODAY
C# for Metro style apps
Windows has always provided compelling capabilities for developers to build upon
Windows has not always made it straightforward for you to use these
capabilities from C# or VB
FACT
[DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindow")]static extern int capCreateCaptureWindow( string lpszWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight, int hwndParent, int nID);
[DllImport("avicap32.dll")] static extern bool capGetDriverDescription( int wDriverIndex, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszName, int cbName, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszVer, int cbVer);
// more and more of the same
A small, easy sample of Win32 code
Traditional Windows API
Your Managed
Code
Manually Generated
Interop Code
There’s a hole somewhere...
On Windows 8, this will now be…
using Windows.Media.Capture;
var ui = new CameraCaptureUI();ui.PhotoSettings.CroppedAspectRatio = new Size(4,3);
var file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file != null) { var bitmap = new BitmapImage() ; bitmap.SetSource(await file.OpenAsync(FileAccessMode.Read)); Photo.Source = bitmap;}
Traditional Windows API
Your Managed
Code
Windows Runtime
The hole is gone
We already have the skills to build Metro style applications using C#
(and VB as well)
FACT
C# and Visual Basic influencedthe Windows Runtime
FACT
Windows Runtime is designed to be used from object-oriented languages
like C# and Visual Basic
FACT
Windows Runtime metadata files use an updated version of .NET’s metadata format
FACT
DEMOUsing ILDASM for Windows Metadata files
Windows Runtime includes a XAML based framework for Metro style apps
(we’ll see that in more detail further)
FACT
Many of the Windows Runtime design guidelines
came from the .NET design guidelines
FACT
Windows Runtime was expressly designed to work well with C# and Visual Basic
FACT
Using the Windows Runtime feels natural and familiar
from C# and Visual Basic
FACT
DEMOUsing the Windows Runtime from C#
Most WinRT types map directly to C#/VB
var ui = new CameraCaptureUI();ui.PhotoSettings.CroppedAspectRatio = new Size(4, 3);
var file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file != null) { var bitmap = new BitmapImage() ; bitmap.SetSource(await file.OpenAsync(FileAccessMode.Read)); Photo.Source = bitmap;}
Almost everything maps directly between the Windows Runtime and .NET
• Primitives(strings, numbers, etc)
• Interfaces• Enums• Structs• Delegates
• Delegates• Constructors• Static Members• Properties• Events• Methods
Most differences between Windows Runtime and
.NET are hidden from the managed developer
FACT
Exceptions from HRESULTs
try
{ var ui = new CameraCaptureUI(); ui.PhotoSettings.CroppedAspectRatio = new Size(16, 9);}catch (Exception e){ //Exception handling code}
ComException
Accessing a WinRT Collection from C#
var picker = new FileOpenPicker();picker.FileTypeFilter.Add("*");var files = await picker.PickMultipleFilesAsync();foreach (StorageFile file in files){ lbFiles.Items.Add(file.FileName);}
System.Collections.Generic.IReadOnlyList <Windows.Storage.StorageFile>
Windows.Foundation.Collections.IVectorView <Windows.Storage.StorageFile>
LEVERAGING TOMORROW WHAT WE KNOW TODAY
XAML for Metro style apps
Focusing now on…
Windows Kernel Services
JavaScript(Chakra)
C/C++ C#, VB
Metro style Apps
Communication & Data
Application Model
Devices & Printing
Windows Runtime APIsGraphics &
Media
XAML HTML / CSS
HTMLJavaScript
CC++
C#VB
Desktop Apps
Win32 .NET SL
Internet Explorer
Moving from current XAML to WinRT
• It’s all XAML– What you know, remains valid
• You as a Silverlight/WPF/WP7 developer can now add Windows 8 developer to your business card!
• If you know C++, you can now integrate that with XAML as well
Concepts that carry forward
• Same control model as we have today in Silverlight and WPF– Many controls can just be copied to WinRT– Same thing, but now native
• Concepts:– Data binding, change notification– Styling– Animations– Visual State Manager– Already seen: C#, VB.NET and C++
• Some things may not be natively supported though• XAML is now exposed as a WinRT API
– No wrappers!
DEMOSilverlight app to Metro app
What do you get as extra?
• WinRT (duh)– APIs are aimed at building Metro style apps only
• Metro style, look and feel• Touch is now fully supported, next to mouse input– Unified under “PointerXXX”
• Metro style controls • New base namespace – Windows.UI.Xaml
• Windows Store
Input is now touch-driven
• Things will still work with a mouse though
DEMOMetro-style UI
Running an application
Tile -> Splash Screen -> App (App UI)
XAML UI Starts Here
Controls for Metro-style apps
List Box
Hyperlink
CheckboxProgress Bar
Text Box
Password
Progress Ring
Tooltip
Grid ViewButton
Flip View
Combo Box
Scroll Bar
Context Menu
Slider
Toggle Switch
Semantic Zoom
Panning Indicator
Navigation
List View
Web View
Radio Button
Clear Button
Reveal Button
Spell Checking
ListView and GridView are the new kids
• Windows 8 “list controls”• Optimized for touch input• Support Windows 8 selection models• UI and Data Virtualization• Built in grouping
DEMOUsing a GridView
And more new controls…
• MediaPlayer• ToggleSwitch• ProgressRing• FlipView• JumpViewer– Semantic Zoom Control– Supports 2 Levels
DEMOUsing a FlipView
The ApplicationBar, another new control
• Used to place commands– “Inherited” from Windows Phone 7
• Persistent, light dismiss or time dismiss• Swipe in from top/bottom to display
DEMOUsing the ApplicationBar
SOME MORE CONCEPTS
Screen resolution and orientation
• Screen resolution:– Current Resolution:
• Window.Current.Bounds
– Event:• Window.Current.SizeChanged
• Orientation– Current (Namespace: Windows.Graphics.Display)
• DisplayProperties.CurrentOrientation
– Event:• DisplayProperties.OrientationChanged
Detecting Layout
• An application should support more than just the default view
• Can detect when the view changes to react by showing another view– ApplicationLayout.GetForCurrentView().LayoutChanged
Snapped Filled Full Screen
DEMOUsing Snapped View
Integrating with Windows
• An application can integrated withWindows and other applicationsthrough the “charms”– Search– Share– Devices– Settings– Picker
• A charm is like a contract, a way of letting applications talk without knowing each other
The “share” charm
• A source app will share something• Target app will get the shared data• Between the two, some common formats are
provided for data interchange• Should your app share?– Yes, most apps that create something should be
sharing data• Should an app be a target?– If your app does things like publishing, storing or
transforming data, then yes.– IM, translator, uploader...
Specifying capabilities
• Just like Windows Phone 7, an application needs to specify what it needs in the Application Manifest– Declare the intent towards system resources
The lifetime of a Metro app
• Only the foreground app is Active• All other background apps are Suspended– They get a notification about it
• While suspended, apps may be Terminated– They won’t be notified about this
Summary
• A new world is opening up• As a developer now– We need to learn some new things– Most of our current knowledge is carried over– Our investments are safe (Silverlight, HTML, C++...)
Q&A
THANKS!
Thinking about the future with Windows 8SILVERLIGHTSHOW.NET WEBINARS SERIESGILL CLEEREN, 29th November 2011www.snowball.be - [email protected] - @gillcleeren