Spearfish French Teacher Promotes Petition Against HB 1234 on TV

Posted by - February 21st, 2012

And in other news, someone let Heidelberger on TV again… Did I mention that Governor Dennis Daugaard’s HB 1234 is a really, really bad idea? Save your school! Sign the petition! Call your legislators! Update 19:57 MST: KDLT found it worth their while to report on the groundswell against HB 1234 as well. KDLT also [...]
Madville Times

Tags: , , , , , ,

Windows 8 and the future of XAML: Part 3: Using WinRT

Posted by - February 20th, 2012

In this third part of our exploration of Windows 8 and WinRT, we’re going to start applying the concepts we learned about in the 2 first parts by using them in code. By now, you should have a good understanding of what Windows 8 Metro style applications are all about. In part 1, we’ve thoroughly explained how Windows 8 applications work inside the Metro environment. We’ve also looked at the improvements made to the desktop mode of Windows 8, which is a place where a lot of us will be spending most of their time I assume.

In Part 2, we’ve seen some very important concepts. We’ve covered WinRT itself: we’ve looked at its architecture and its cornerstones, such as the runtime broker, Windows Metadata and asynchronous development. We’ve also touched on the Windows 8 tailored profile.

This brings us to Part 3. In this article, we’ll start writing code that makes use of WinRT components. Although most of us like to write XAML and C# code, we’ll leave the regular path for once and we’ll write some JavaScript/HTML as well. After some “Hello Worlds”, we’ll dive in more advanced concepts including Capabilities, the Share contract, working with the webcam and some more. Here we go!

Hello World… This time for real

In part 2, I already had the same heading. However, we hadn’t really written any code yet. So let’s do that right now. Note that for all the code we are writing here, you need Visual Studio 11 Express for Windows Developer Preview installed on a Windows 8 machine. To keep things simple, when I use the term”Visual Studio” from now on, it’s this version I’m referring to. If you have Visual Studio 11 installed on your Windows 8 environment as well, the templates that come with the Express edition will also be added to VS11.

A small disclaimer is in place here: the code written in this article is written and tested on the developer preview and may not work correctly with later releases.

Hello Visual Studio

When opening Visual Studio, you’ll notice that things haven’t changed a lot (of course, at the time of writing, we’re using a very early version). When clicking on the New Project link on the Start Page, you get the New Project dialog, shown below.

clip_image002

In part 2, we talked about the so-called language projections of WinRT. A language projection makes it possible to use WinRT, which is written in native code, from another language. Because of this, developers can keep using the language of their choice to write Metro style applications. The language projection makes sure that language constructs remain intact. Things like a constructor, the var keyword, the await keyword all remain the same if you choose to use WinRT from C#. The language projections that are available can be seen here: we can build Metro style apps from JavaScript, C#, VB and C++. All languages have the same project templates available as well.

Let’s start by selecting the C# option. Create a new project (just select the regular Application template for now) and name it HelloWinRTFromCs. Visual Studio opens a designer that should look familiar to the Silverlight developer. We have our regular drag-and drop interface and a XAML editor, as shown below.

clip_image004

In the XAML editor, we can start writing our typical “Hello World” application as follows:

<UserControlx:Class="HelloWinRTFromCs.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="768"d:DesignWidth="1366">

    <Grid x:Name="LayoutRoot"Background="#FF0C0C0C">

        <TextBlock Name="HelloWorldTextBlock" FontSize="42" Margin="20"></TextBlock>

        <Button Content="I'm the Hello World generator button" Name="HelloWorldButton"

            Click="HelloWorldButton_Click"></Button>

    </Grid>

</UserControl>

In the event handler of the Button, we write the following code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Windows.Foundation;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Data;

 

namespace HelloWinRTFromCs

{

    partial class MainPage

    {

        public MainPage()

        {

            InitializeComponent();

        }

 

        private void HelloWorldButton_Click(object sender, RoutedEventArgs e)

        {

            HelloWorldTextBlock.Text = "Hello World from SilverlightShow";

        }

    }

}

Ready? Start your debugging engines! Simply hit F5 as you’re used to. Your first Windows is now being prepared. If you take a look in the Output Window, you can see that an *.exe is being created and that *.exe is being packaged into an *.appxrecipe. This file is basically the deployment file that will be “hosted” inside of the Metro environment. After a few seconds, you’ll see your Metro app up and running as shown below. Hit the Button and you’ll be greeted with a nice Hello World from your app when you click the button.

clip_image006

Visual Studio also comes with a simulator. To use it to test your app on, simply select it from the debug options. The simulator is shown below.

clip_image008

Hello C++

Managed developers should feel reassured already a bit now that they’ve seen that it’s pretty much the same thing we’re doing to build a Metro style app. But what about C++ developers? Let’s build the same app but now from C++. The XAML code can be directly copied and pasted inside the new project. This will work since all XAML classes (such as Button and TextBlock) have now moved into the Windows.UI.Xaml namespace. This namespace is part of WinRT and it is thus the same one we’re using in both C# and C++.

The C++ code for the event handler is shown below.

void Application33::MainPage::HelloWorldButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)

{

HelloWorldTextBlock->Text = "Hello World";

}

When running the application, you should get the exact same result. Behind the scenes, our C++ code is being compiled into a native x86 instruction stream (if we would be running this on an ARM-based device, this would be an ARM instruction stream). C++ is directly interacting with the WinRT components.

And why not… Hello JavaScript and HTML

To make the circle complete, let’s write a Hello World app from JavaScript as well. Of course, we’re unable to copy the XAML; JavaScript works in combination with HTML code. Create a new project and select JavaScript this time.

In the HTML code, write your Hello World app as follows:

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8" />

    <title>WinWebApp6</title>

    <!-- WinJS references -->

    <link rel="stylesheet" href="/winjs/css/ui-dark.css" />

    <script src="/winjs/js/base.js"></script>
   1:  

   2:     <script src="/winjs/js/wwaapp.js">

   1: </script>

   2:     <!-- WinWebApp6 references -->

   3:     <link rel="stylesheet" href="/css/default.css" />

   4:     <script src="/js/default.js">

</script>

</head>

<body>

    <b>Hello World</b>

</body>

</html>

More WinRT

Although new development platform or language you learn starts with Hello World, it doesn’t get you very far. Let’s look at some more concepts.

Selecting files on the local file system using the FileOpenPicker

Metro apps can’t directly access system resources such as the file system. It’s pretty much the same story as Silverlight that we have here: in-browser Silverlight apps can only get access to file if the user selects the file through an OpenFileDialog. In that case, Silverlight gets read-only access to the file. Apps with elevated permissions can get access to the local system.

In WinRT, we have file pickers. Such a picker allows the user to select a file on the “underlying” Windows desktop environment. In the following code, we are using the FileOpenPicker to allow the user to select an image, which we’ll then display in an Image control.

private async void SelectImageButton_Click(object sender, RoutedEventArgs e)

{

    var filePicker = new Windows.Storage.Pickers.FileOpenPicker();

    filePicker.FileTypeFilter.Add(".png");

    var selectedImageGuFile = await filePicker.PickSingleFileAsync();

 

    BitmapImage bitmapImage = new BitmapImage();

    bitmapImage.SetSource(await selectedImageGuFile.OpenAsync(Windows.Storage.FileAccessMode.Read));

    myImage.Source = bitmapImage;

}

Notice the line where we are selecting the file. It makes use of the await keyword. Every call that can take longer than 50ms is done asynchronously by default in WinRT. Silverlight developers are already used to writing async code: when accessing a service, this is the default. Traditionally, we solved this with a callback method. There’s nothing wrong with that. However, this new approach using the await keyword, makes things cleaner: all the lines that are behind the line with the await keyword are only executed when the asynchronous call is completed. Note that the method itself has the async keyword added to it.

When clicking the Button, the file picker displays itself as follows:

clip_image010

Again, through language projections, the asynchronous development is made natural in the language. In JavaScript, the same can be achieved through a JavaScript promise:

var picker = new Windows.Storage.Pickers.FileOpenPicker;

picker.fileTypeFilter.append(".jpg");

picker.pickSingleFileAsync().then;

Accessing the picture library and Capabilities

Next to the pickers API, Metro-style applications can also access some folders directly such as the pictures library. Although stating “directly” may not be very good, let me explain.

In Windows 8, Metro style applications can declare capabilities. A capability is a way for the application to declare that for it to function properly, it needs to have a certain permission. Such a permission can be accessing the webcam, sending text messages, accessing the picture, movie or documents library and quite a few more. This information will be used in the Windows Store: with this information, the Windows Store can notify the potential user that the application will have the declared permissions so that the user may decide on not installing the application. This is the same process as in the Windows Phone Marketplace.

Let’s take a look at working with capabilities. We’ll try them out using a project which can access the picture library. Create a new C# project and name it WorkingWithCapabilities.

To define a capability, we can open the appxmanifest file, included in each Metro style project. In the Capabilities tab, check the “Picture Library Access”.

clip_image012

In the XAML, add a GridView (we’ll look at the GridView later on, for now, just remember that it’s a control allowing you to scroll through items horizontally) as follows:

<GridView Name="PicturesGridView" Height="500" VerticalAlignment="Center"></GridView>

In the code-behind, add the following code:

public MainPage()

        {

            InitializeComponent();

 

            LoadImages();

            

        }

 

private async void LoadImages()

{

    StorageFolder picturesFolder = KnownFolders.PicturesLibrary;

 

    IReadOnlyList<IStorageFile> fileList = await picturesFolder.GetFilesAsync();

 

    foreach (IStorageFile file in fileList)

    {

        if (file.FileType.Equals(".JPG"))

        {

            var bmp = new BitmapImage();

            var f = await file.OpenAsync(FileAccessMode.Read);

            bmp.SetSource(f);

            Image image = new Image();

            image.Width = 200;

            image.Height = 200;

            image.Source = bmp;

            imageControls.Add(image);

            image.Tag = file;

        }

    }

    PicturesGridView.ItemsSource = imageControls;

}

Notice that we are accessing the Picture Library through the use of the KnownFolders enumeration, which gives us access to the folder from code. This code will however only work when you have indicated in the Capabilities tab that your app needs access to this folder. Then, we read out the files through another async call (remember, we are accessing the drive, which could be a slow process, hence, the async call). Finally, through data binding, we bind a list of images to the GridView. The running app is shown below:

clip_image014

Summary

In this article, we have done our first development in WinRT. We have looked at the first concepts as well, such as the file pickers and the capabilities. In the next article, we’ll continue on this path, exploring more concepts such as contracts/charms in Windows 8.

About the author

Gill Cleeren is Microsoft Regional Director (www.theregion.com), Silverlight MVP (former ASP.NET MVP) and Telerik MVP. He lives in Belgium where he works as .NET architect at Ordina (http://www.ordina.be/). Passionate about .NET, he’s always playing with the newest bits. In his role as Regional Director, Gill has given many sessions, webcasts and trainings on new as well as existing technologies, such as Silverlight, ASP.NET and WPF at conferences including TechEd Berlin 2010, TechDays Belgium – Switzerland – Sweden, DevDays NL, NDC Oslo Norway, SQL Server Saturday Switserland, Spring Conference UK, Silverlight Roadshow in Sweden, Telerik RoadShow UK… He’s also the author of many articles in various developer magazines and for SilverlightShow.net and he organizes the yearly Community Day event in Belgium. He also leads Visug (www.visug.be), the largest .NET user group in Belgium. Gill recently published his first book: “Silverlight 4 Data and Services Cookbook” (Packt Publishing). His second book, Silverlight 5 Data and Services Cookbook will be released March 2012. You can find his blog at www.snowball.be.

Twitter: @gillcleeren

SilverlightShow: Silverlight Community

Tags: , , , , ,

Petition: Stop HB 1234, Convene Task Force on K-12 Education

Posted by - February 16th, 2012

South Dakota’s schools deserve solutions that work. Sign this petition to tell Governor Daugaard to take time to find the right solutions. Governor Dennis Daugaard insists that South Dakota’s schools are failing, even though neither he nor anyone else has clearly defined just what the problem with our K-12 system is. The Governor says drastic [...]
Madville Times

Tags: , , , , , ,

Daily News Digest 2/13/2012

Posted by - February 13th, 2012

Subscribe to our Daily News Digest RSS Feed to receive a summary of all SilverlightShow news!

Here is the new SilverlightShow content for Monday, February 13th, 2012.

Missed last week’s news? Check them out at our End-of-week Content Recap!

SilverlightShow: Silverlight Community

Tags: , , ,

Upcoming SilverlightShow Webinar: Windows Phone Raw Camera Access

Posted by - February 13th, 2012

Upcoming SilverlightShow Webinar: Windows Phone Raw Camera Access
 

March 15th, 2012, 11 am PDT (check your local time)

Register for this webinar
 


Webinar topic summary:

Starting with the “Mango” release, developers have programmatic raw access to the cameras on Windows Phone devices. This enables a whole set of new possibilities for application authors, for example to capture video and stills, to perform real-time manipulation of the camera feed, and to create augmented reality scenarios. 

In this webinar, we will learn how to access and integrate the camera feed in our applications, work with some of the related features like choosing between the main and front-facing cameras, adjusting focus and using the flash, and see how to access and manipulate raw image data. We will also learn about limitations and potential problems you will run into when you work with raw camera access.

Presenter: Peter Kuhn. 

Give your feedback on this webinar in our post-webinar survey! Three if you will win Peter’s SilverlightShow ebook ‘Getting Ready for The Windows Phone 7′ Exam 70-599′.

Sign up as a Silverlight Show member or follow us on Twitter / join our LinkedIn Group to get notified about next scheduled SilverlightShow webinars. Or, visit our webinars page.

 

About the webinar presenter:


Peter KuhnPeter Kuhn, aka “Mister Goodcat” is an MCPD for .NET, Silverlight and Windows Phone 7, and has earned the Microsoft Community Contributor award in 2011. He has more than ten years of experience as developer, project lead and technical director. Today he works as trainer for Microsoft .NET, Silverlight business application development and the Windows Phone 7 platform (both Silverlight and XNA), and as technical author. You can find his trainings and more info on http://www.goodcat-trainings.net/.

Peter is the author of many SilverlightShow articles, among which the appreciated 14-part article series ‘XNA for Silverlight Developers’ (also available as an ebook) and ‘Getting Ready for the Windows Phone Exam 70-599′ (available as an ebook too). He also delivered the following SilverlightShow webinars:

Who is this webinar appropriate for:
Windows Phone developers
    
Duration:
60-70 minutes, including Q&A

Technical Requirements:
Internet connection and computer speakers for audio.

Want to see more scheduled or past webinars? Check SilverlightShow Webinars page.

  

SilverlightShow: Silverlight Community

Tags: , , , , , ,

End-of-week SilverlightShow Content Recap (2/10/2012)

Posted by - February 12th, 2012

Below you may find a summary of all new content we’ve published on SilverlightShow throughout the week February 6-12, 2012:

New Article Series

How should you develop your apps for multitude of devices (on the net, on a desktop, on a phone, on a tablet, …)? Are there best practices? Can you reuse code, and if yes, should you? How can you keep costs in check?

Find out the answers of all these questions in Kevin Dockx’s new article series for SilverlightShow, by building the same type of application as an HTML5, Silverlight (web), Silverlight (OOB), Windows Phone and Windows 8 Metro application. The first two parts of this series available here:

Webinar News

February is definitely a month of great Gill Cleeren’s webinars! This week, Gill delivered the second part of his session “Metro and WinRT for the Silverlight/WPF Developer” (watch recording of Part 1/get demos & slides). Below is some information related to this live session: 

Also, check out SilverlightShow Webinar Newsletter for February online! Be the first to find out about new webinars and updates by registering at SilverlightShow and enabling the newsletter option in your member profile.

Ebook News

Check out SilverlightShow ebook offer for February (valid thru Feb 29th). Get a bundle with our most popular article-based ebooks with more than 40% off. The full offer available here:


SilverlightShow Contest

SilverlightShow and Visual Studio Live are giving away one free pass (,095 value) for Visual Studio Live! Las Vegas event taking place March 26-30, 2012 in Mirage Resort & Casino, Las Vegas! Complete a simple sentence, and you are in for the draw. Check out the complete contest rules:

See which are the two Silverlight/WPF sessions that will grab your attention at the Visual Studio Live! Las Vegas Conference!

50+ fresh new stories by our valued bloggers and community sites

Top 5:

All other news we published:

Monday (February 6th, 2012)

Tuesday (February 7th, 2012)

Wednesday (February 8th, 2012)

Thursday (February 9th, 2012)

Friday (February 10th, 2012)

Enjoy your weekend and return at SilverlightShow on Monday for a whole new week full of exciting news and content!

SilverlightShow: Silverlight Community

Tags: , , , ,

Drug Testing Poor, Vaccination Paranoia Fail in SD Legislature

Posted by - February 9th, 2012

As the bad news rolls in about the South Dakota Republican Party’s continuing war on teachers, I take small comfort in seeing our legislators having the good sense to whack at least a few bad ideas. I noted the demise of Wisconsin-style union bashing, home school handouts, and bad interstate insurance policy earlier; now I [...]
Madville Times

Tags: , , , , , ,

End-of-week SilverlightShow Content Recap (2/3/2012)

Posted by - February 5th, 2012

Below you may find a summary of all new content we’ve published on SilverlightShow throughout the week January 30 – February 5, 2012:

New Articles

Webinar News

Ebook News

Forum News

50+ fresh new stories by our valued bloggers and community sites

Top 5:

All other news we published:

Monday (January 30th, 2012)

Tuesday (January 31st, 2012)

Wednesday (February 1st, 2012)

Thursday (February 2nd, 2012)

Friday (February 3rd, 2012)

SilverlightShow: Silverlight Community

Tags: , , , ,

Stephanie Strong Opens Weak Website

Posted by - February 4th, 2012

MDR’s Tom Lawrence gets Stephanie Strong on the record for her reasons for challenging Rep. Kristi Noem to a Republican primary. God made America a superpower, don’t raise debt limit, Kristi gone Washington, lives torn apart by welfare… …yadda yadda yadda. Check out the link at the bottom of the MDR story: StephanieStrongCongress.com! Whoo-hoo! Let’s [...]
Madville Times

Tags: , , , ,

Christian Bias in Public School Speeds Through Legislature

Posted by - January 31st, 2012

Neither vote on Hickey legislation went the way I wanted it yesterday. The Senate approved Rep. Steve Hickey’s silly Bible-study-in-public-school resolution, HCR 1004, and didn’t have the courtesy to add a clause putting conscientious and unbiased secular humanists in charge of such literary instruction. Meanwhile, across the hall, the House killed Rep. Hickey’s perfectly sensible speeding [...]
Madville Times

Tags: , , , , , ,

« Previous Entries