460 likes | 660 Views
Building Windows Store Apps with XAML or HTML . Ilja Tšahhirov Skype. Agenda. WinRT supported languages. UI for .NET developer. UI for JavaScript developer. Components authoring. Language - alternatives. .NET ( C#/VB). JS. C++. Combined.
E N D
Building Windows Store Appswith XAML or HTML Ilja TšahhirovSkype
Agenda WinRT supported languages UI for .NET developer UI for JavaScript developer Components authoring
Language - alternatives .NET ( C#/VB) JS C++ Combined • UI (JS/C#/VB/C++) + WinRT component(C#/VB/C++)
Windows Runtime Architecture Language Support (CLR, WinJS, CRT) Windows Store app Language Projection Windows Metadata & Namespace UI Pickers Controls Media Web Host (HTML, CSS, JavaScript) XAML Storage Network … Windows Runtime Core Runtime Broker Windows Core
* Pick a language you are most comfortable withBefore using combined approach, understand why
Windows 8 Windows 8 Store Apps Desktop Apps HTML JavaScript CSS HTML / CSS XAML View JavaScript (Chakra) C C++ C# VB Model Controller C# VB C C++ WinRT APIs Devices & Printing Communication & Data Graphics & Media Devices & Printing Communication & Data Graphics & Media System Services System Services .NET / SL Internet Explorer Win32 Application Model Application Model Windows Core OS Services Windows Core OS Services Core Core
Key Aspects Lost of knowledge can be re-used Process lifecycle considerations Battery life considerations WinRTAPIs Async
You already have the skills to build Windows Store apps with C# and VB
Application lifecycle Running Suspended Terminated
Battery life Use system resources with care (e.g. threads vsasync) Background activity – limit to absolute minimum (if possible – don’t do anything at all) Background activity resource quotas
Windows has always provided features for developers to build upon
Windows hasn’t always made it easy for developers to use these features from C# or VB
The C# code you have to write today… [DllImport("avicap32.dll", EntryPoint="capCreateCaptureWindow")]static extern intcapCreateCaptureWindow(stringlpszWindowName, intdwStyle, intX, intY, intnWidth, intnHeight, inthwndParent, intnID); [DllImport("avicap32.dll")] static extern boolcapGetDriverDescription(intwDriverIndex, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszName, intcbName, [MarshalAs(UnmanagedType.LPTStr)] ref string lpszVer, intcbVer); // more and more of the same
Your Managed Code Manually Generated Interop Code Traditional Windows API
The C# code you get to write on Windows 8 using Windows.Media.Capture;varui = newCameraCaptureUI();ui.PhotoSettings.CroppedAspectRatio = newSize(4, 3);varfile = awaitui.CaptureFileAsync(CameraCaptureUIMode.Photo);if(file != null) {var bitmap = newBitmapImage() ; bitmap.SetSource(awaitfile.OpenAsync(FileAccessMode.Read)); Photo.Source = bitmap;}
Your Managed Code Windows Runtime Windows 8 API
demo Photo capture application
Windows Runtime Architecture Language Support (CLR, WinJS, CRT) Windows Store app Language Projection Windows Metadata & Namespace UI Pickers Controls Media Web Host (HTML, CSS, JavaScript) XAML Storage Network … Windows Runtime Core Runtime Broker Windows Core
Using the Windows Runtime feels natural and familiar from C# and Visual Basic
Almost everything maps directly between the Windows Runtime and .NET Primitives(strings, numbers, etc) Interfaces Enums Structs Delegates Classes Constructors Static Members Methods Properties Events
Most differences between Windows Runtime and .NET are hidden
.NET automatically maps collection interfaces to their Windows Runtime equivalent IEnumerable<T> IIterable<T> IList<T> IVector<T> IReadOnlyList<T> IVectorView<T> IDictionary<K,V> IMap<K,V> IReadOnlyDictionary<K,V> IMapView<K,V>
Synchronous vs. asynchronous var data = DownloadData(...); ProcessData(data); STOP DownloadData ProcessData varfuture = DownloadDataAsync(...); future.ContinueWith(data => ProcessData(data)); DownloadDataAsync ProcessData
Asynchronous programming models Windows Runtime: IAsyncOperation<T> .NET Framework: Task<T> Javascript: Promises All are objects representing “ongoing operations” All use callbacks to signal completion of operation Callbacks turn your code inside out
Asynchronous methods automatically transform normal code into a callback state machine
Asynchronous methods in .NET Are marked with new “async” modifier Must return void or Task<T> Use “await” operator to cooperatively yield control Are resumed when awaited operation completes Allow composition using regular programming constructs Feel just like good old synchronous code!
demo Asyncin WinRT
Windows 8 Windows 8 Store Apps Desktop Apps HTML JavaScript CSS HTML / CSS XAML View JavaScript (Chakra) C C++ C# VB Model Controller C# VB C C++ WinRT APIs Devices & Printing Communication & Data Graphics & Media Devices & Printing Communication & Data Graphics & Media System Services System Services .NET / SL Internet Explorer Win32 Application Model Application Model Windows Core OS Services Windows Core OS Services Core Core
JavaScript Windows Apps • In essence – Web app hosted locally • Hosted at WWAHost.exe • Under certain circumstances parts of the app can be executed under different host • Certain WinRT features (available under .NET / C++) unavailable
From IE10 web app to Windows app • Minor API differences http://msdn.microsoft.com/en-us/library/windows/apps/hh700404.aspx • Different host • No plug-ins in Windows apps • Trust level differences (local and web context) • http://msdn.microsoft.com/en-us/library/windows/apps/hh465373.aspx • UX [recommended] • Windows 8 features [recommended]
Context in HTML/JS Windows apps There are ways to communicate across contexts, ways to give websites access to some web standards features and ways to skip automatic filtering within a function.
demo Visual Studio 2012
You can build managed WinRT components that project into C++ or JavaScriptby following a few simple rules
Only the public types and members in your managed WinRT components need to follow these simple rules
Structs can only have public data fields API signatures must use only Windows Runtime types All types must be sealed (excempt XAML controls) Only supports system provided generic types
Visual Studio has built-in support for managed Windows Runtime component projects
demo Building Windows Runtime Components in C#
You already have the skills to build Windows Store apps with JS, C# and VB
For the UI pick a language you are the most comfortable with*Use AsyncIf needed, can build your own Windows Runtime components use them from the UI