Building Windows Store Apps with .NET

Building Windows Store Apps with .NET

Rate This
  • Comments 11

For .NET developers, this is the best time to build client apps. Never before have the Windows APIs been so easy to use from C# or Visual Basic without wrapping them with custom libraries. So far, we’ve seen some amazing apps in the Windows Store built using C#. Richard Lander, program manager for the CLR and frequent contributor to this blog, provides the highlights and references for building your Windows Store apps with .NET. -- Brandon

The Windows Store is a new opportunity

Windows 8 redefines apps on Windows, improving both the experiences of creating apps and, most importantly, in using them. The Windows Store provides a new opportunity for you to distribute and sell the apps that you create. Millions of end-users around the world will be looking for apps in a single place, in the Windows Store. Your app might be just the one that they are looking for. That’s a new and compelling proposition.

As a .NET developer, you’ll find that there are multiple new development options available for you to build compelling Windows Store Apps using .NET. .NET code can be used for user interface, business logic and background processing. You can continue to use .NET on the server too, as the implementation of REST, WCF or ODATA APIs that you call from within your Windows Store Apps. For all apps, .NET is a great choice for server logic.

Your app goes here.

image

Getting started writing .NET apps

The best way to get started is to download the tools, including Visual Studio 2012 and Blend for Visual Studio 2012. You will find several templates for .NET apps. In less than an hour, you can download and install everything you need, try out the templates and actually build the beginnings of your first real Windows Store app.

Visual Studio Express for Windows 8 is free to use and you can build your entire app with it alone. You just need Windows 8 and an internet connection to download the tools. From there, you are on your way. If you don’t have Windows 8, you can install a free evaluation copy for developers. If you already have Windows 8 and Visual Studio 2012, then you don’t need anything more.

I have been using the Windows SDK samples a lot. There are samples for most of the UI patterns and technologies that you will use to build Windows Store Apps. For example, there are samples dedicated to snap, semantic zoom, Lock screen presence, XAML data binding and file access. These samples are a great way to quickly learn how to add something to your app or can provide exactly the insight you need to get something to work.

MSDN documentation has all of the reference topics you need to learn more about APIs and new concepts. The documentation is split into Windows.* WinRT APIs and the System.* .NET for Windows Store APIs. You can also browse the .Net Framework APIs within the .NET Framework 4.5 class library. That documentation clearly displays which APIs are available for Windows Store apps, with a small green shopping bag. You may also want to read the post that we published on the .NET APIs for Windows Store Apps earlier in the year, on this blog.

There is also another blog dedicated to discussing Windows Store app development. You will want to consult it, as it goes into a lot more detail about Windows Store apps, including apps written with .NET.

Windows 8 adds the Windows Runtime

Before you get too far into building Windows Store Apps, you will benefit from a basic understanding of the Windows Runtime (WinRT). The WinRT is a new subsystem within Windows that forms much of the foundation of Windows Store apps. Most of the new Windows APIs that you will use are exposed via the WinRT. The .NET APIs are not exposed via WinRT, but continue to work as they always have, exposed by the CLR.

.NET developers are not strangers to interop technologies. You can use both COM Interop and P/invoke to call into native APIs from .NET code. The Windows Runtime is a big step ahead for .NET developers, resolving challenges with those existing interop technologies. It establishes a level playing field across languages, enabling C#, Visual Basic, C++ and JavaScript to depend on the same set of APIs in the same way.

All languages use the same metadata format for describing WinRT APIs. In fact, this metadata form is CLR metadata, with a small set of tweaks. As a result, it was very easy for Visual Studio to create an IntelliSense experience for WinRT APIs that is similar to the .NET Framework and for the .NET compilers to reference WinRT metdata. You can open WinRT metadata files, called WinMDs, in ILDasm and Reflector! In addition to being able to call WinRT APIs, you can use C# and VB to create Windows Runtime Components, which expose WinRT APIs.

Shawn Farkas, from the Common Language Runtime team, published a very useful and technical MSDN Magazine article on Windows Runtime interop with managed code, called Underneath the Hood with .NET and the Windows Runtime. It will answer many of the lower-level questions that you might have about how managed code can WinRT interoperate.

Resource: NET Framework Support for Windows Store Apps and Windows Runtime

Writing Windows Store XAML Apps

Many of you will see a natural affinity between XAML and .NET. You may have experience building Silverlight and WPF apps, which also use XAML. If you are familiar with XAML, then Windows Store XAML apps will be a natural fit. You will find that you are immediately comfortable with and able to build Windows Store XAML apps. The code-behind model is the same and the XAML syntax is largely what you’ve used before. You can continue to use your preferred design pattern, such as MVVM or MVC. You can read about the differences in the XAML porting guide

Visual Studio 2012 makes it easy to build XAML apps, using a new designer for XAML apps. You can also use Blend for Visual Studio 2012 to create visually compelling apps. The process of creating XAML apps is very similar in practice to what you are used to. The main difference is that all of the XAML APIs will appear in Windows.UI.XAML instead of System.Windows.

Resource: XAML overview (Windows Store apps using C#/VB/C++ and XAML)

Resource: Quickstart: Create a UI with XAML (Windows Store apps using C#/VB/C++ and XAML)

XAML App Windows 8 SDK Sample

I’ve included a screenshot of a XAML app from the Windows 8 SDK, called XAML essential controls sample. This sample demonstrates the basic set of XAML controls you have available. The screenshot demonstrates the progress bars available within XAML apps. You can look at the many other XAML samples available in the Windows 8 SDK, in C# and VB.

image

Updated XAML App Windows 8 SDK Sample

The sample above is largely composed of XAML, without code affecting the presentation of the controls. I’ve made a small update to the sample to show you how you can write C# code that modifies the controls that you see above. All of the XAML controls that are built-in to the platform have been built with C++ and are exposed by WinRT for both .NET and C++ callers. That means, the C# code that you will see below needs to call through WinRT in order to update the controls. You will quickly notice that while the code calls into WinRT, that it looks like .NET code, and is very similar to the code that you would write for the other XAML platforms (Silverlight, WPF) that expose a managed code surface area.

I added a button to the XAML (“Update Progress”, below), which is intended to update the state of the determinate progress bar, otherwise set to a constant 30%. Within the Visual Studio 2012 XAML designer, I double-clicked on the button to create an event handler for the click event for the button. Last, I wrote this small bit of code to update the progress bar with each button click. All of the code you see below is .NET code, however, the two calls to determinateProgress.Value are interop calls via WinRT. The WinRT calls blend in very cleanly with the rest of the code that you write. The objects in the method signature are also WinRT objects, however, I am not using them in this sample.

private void Button_Click_1(object sender, RoutedEventArgs e)
{
var currentProgress = determinateProgress.Value;

currentProgress += 10;
if (currentProgress > 90)
currentProgress = 10;

determinateProgress.Value = currentProgress;
}

You can see the updated SDK sample below, with the addition of my button. Notice that the progress bar is in a different place. I clicked it a few times before I took this second screenshot.

image

Writing Windows Store DirectX Games -- SharpDX

DirectX games written in C# are another popular option that we are seeing, including games built by Microsoft. The Windows 8 SDK does not include a DirectX API for .NET developers, but only for C++. Fortunately for you, the open source SharpDX DirectX SDK is available to .NET developers to write Windows Store apps. It should also be noted that you can create a XAML app with .NET that hosts DirectX component s written in C++.

In addition, Unity has announced that they will support their Unity3D game engine for .NET developers, for Windows Store apps and Windows Phone 8. This release is still pending and doesn’t have a specific release date.

SharpDX is a low-level set of managed wrappers over the native DirectX API. These wrappers are tool-generated directly from DirectX header files, which enables them to be complete and also results in them including just the minimal interop code necessary to call the native APIs. It supports all of the DirectX API, including 2D, 3D, Sound and Input. You can get the SharpDX SDK from the SharpDX site. An update to SharpDX 2.4 was recently released, and also supports Windows Phone.

The following screenshot demonstrates a sample SharpDX app, which is a spinning cube.

image

The following screenshot shows some of the code that displays the spinning cube above, in Visual Studio 2012.

image

Closing

The Windows Store creates an important new opportunity for you, with Windows 8. More than 1,000 PCs and tablets, including Microsoft Surface, are available for consumers and businesses to buy. I expect that the Windows Store app within Windows 8 will be a frequent destination for users, wanting to find apps that meet their needs and interests. That app might be yours. The proposition to developers is a unique one, given that there are over 1 billion Windows users worldwide. Many of these users will approach the Windows Store with fresh enthusiasm, having never experienced an app store before. Your app might become part of their daily routine and part of their lives.

You can create .NET apps with XAML UI. For games, you may choose one of the DirectX SDKs that 3rd party groups have already made available. It really is a great time to be a .NET developer. The Windows Store provides great ways to build your app with the .NET technologies that you’ve already learned. Visual Studio 2012 and the .NET Framework 4.5 are available to help you build .NET Windows Store apps. The Windows Store is open to developers in 120 countries around the world. Users and businesses will start buying Windows 8 in large numbers. The only thing left is your app.

Once again, please do check out the Windows 8 app developer blog to learn more about Windows Store development.

Follow us or talk to us on Twitter -- https://twitter.com/dotnet.

Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post
  • I love C#, it's an awesome language - it's so much easier to work in than others and .NET is a superb platform, all this Windows store stuff sounds like it's to the detriment of .NET, which is a real shame and needs to be fixed.

    Why is there no consistent message from Microsoft with regard to XNA replacements - that's all it would take?!?  One article suggests monogame, another unity, another SharpDX - none of the C# suggestions work on the Xbox.  None of which are supported well.  C# was making good in-roads in game development but has definitely been replaced by OpenGL and C++ since you guys scared the games industry (hopefully it's a fad but recruiters changed their tone almost overnight).

    OpenGL and C++ are not suitable targets for the Windows store, which knocks your platform out of the park; and you're insistent on avoiding support for it or rubber stamping an alternative officially.  I don't get your intentions, it seems to be to self destruct which isn't in anyone's interest.

  • Thanks for that blog entry.

    Nevertheless Simon makes some good points there. With C# you have the smartest designed language - you really should be commited to it and embrace it more. All these guys like Lippert and Heilsberg do awesome work in that space.

  • Three things are turning me off from writing Windows Store apps.

    The first two might be considered petty: I really don't want to interact with Windows 8 or Visual Studio 2012 any more than I have to, for reasons that have been brought up by thousands of customers in Microsoft feedback forums and covered by every blogger who has written about either offering. But in theory, I could set up a VM or a separate laptop with W8 and VS2012 that I only used for writing Windows Store apps.

    The third, though, is a bigger issue: the flavor of .NET that's available to Windows Store apps breaks compatibility with what we've all known as .NET for a decade, by removing members from such basic types as System.Type. Not only does that mean I can't reuse my old code -- like the game engine that currently runs on .NET, Mono, and Silverlight -- but it also casts doubt on Microsoft's promises about openness. The framework supported by Windows Store apps is not the framework standardized through ECMA and covered by public patent covenants. If I adapt my code to that framework, I have to assume it will never be able to compile on a non-Microsoft platform again.

  • @Simon, I'm glad to hear you've had great experiences with C# and .NET. I am curious why Windows Store is a detriment to .NET? It's not clear to me what problem you're suggesting needs to be fixed.

    Regarding your later comments. DirectX is the equivalent of OpenGL. Many developers who program on Windows and other platforms are familiar with writing portable code between OpenGL and DirectX -- there are plenty of resources for this. Of course, C++ is the language of choice when writing portable graphics intensive code.

  • Thank you so much for this post.  I believe that Microsoft has made a big mistake by leaving the developer community in the dark regarding the choices made when releasing windows 8.  With that being said, this blog answers many questions that I've had about .NET's place in a WinRT world.  I agree with many of the concerns about the new subset of .NET breaking comparability.  I'm very annoyed by the fact that I can't use my existing WPF applications when creating windows 8 applications.  Once again, wonderful post!

    Buddy James

    www.refactorthis.net

  • It would be really nice to see a link to where this SharpDx sample lives...

  • @Stephen

    - Download and extract latest SharpDX "Full Package" from http://sharpdx.org

    - Go to the Samples directory

    - Open SharpDXToolkitSamples.sln solution

    - Compile and run the project MiniCube.WinRT

  • 제어판에서 제거하기 전에는 see you microsoft net frane work4 for new in make all 이전에는 비스타 비타에 대해

    정의는 중요할자료에서 windows xp.vista.offle2000.2003.no2005문제는 2007.2010까지 다시말하면 많은 업데이트.파일.폴더를 너무 크다 see you windows xp.windows vista.windows serves2000.2003.2008.2008r2.2010.미래도 계속 2011.windows7 yes? new in window8 미래도 계속 windows9.10 cnt.le6.le7.le8.le9.le10까지 do see you for microsoft

    net franework4 for all in 11.20.25.30.중요3.5.40.45까지 비트32 for 비트64 no yes see you 비트68keep and sll6.0.7.0.7.5까지 중요할 업데이트.파일.폴더를 pc복사를 보관 있어요 why you new in windows7?2010?4.5?aspnet?그의 문제가 nogooki? yes gooki? microsoft에 문의 바람 이모든 가능합니다

  • What we need is SILVERLIGHT  V6 which is cross platform!

  • @Stephen download the full package on SharpDX.org site it has plenty of good samples including Windows Store app style examples.

    For BJames you can use your existing WPF apps for Windows 8 just can't put them in the app store (but your old win 7 apps aren't in the store either) so not really a big one. You can still make WPF apps for Win 8 even .net 4.5. The confusion as far as I can tell is many people assume only windows app store style apps can be used for win 8 (which simply isn't true).

  • Thanks for the blog. It is really helpful.

Page 1 of 1 (11 items)