Category Archives: Metro

Coding using the new Metro style in Windows 8

Dot Net Framework in Windows 8?

Recently more and more people have been asking me about whether or not WinForms will be in Windows 8.  A more serious question has also been whether or not the Dot Net Framework will be in Windows 8, which would be a huge drawback if it were not.  The framework is far from over, as it is a foundation to how most developers write code for the Windows platform.  Whether or not you know you are using .NET albeit in WPF or through WinForms you are using DotNet.

That being said, Microsoft will likely not cancel their support for their own framework in the new operating system, but expand upon it to provide more useful functionality to developers.  Officially, Microsoft stopped supporting WinForms in Visual Studio 2005 and has not touched it since.  There have been random hot fixes but no new major development and more important no developer support.  Whether or not developers will be forced to move to WPF instead of WinForms to take advantage of the new functionality of Windows 8 is yet to been, but the dying support levels for WinForms should be reason enough to move.

As for any language barriers, just like with any coding language at some point it will die out and you will have to learn something new.  My advice to any developer or user of the Windows platform who is afraid of learning something new is to give up the fear.  We will all move forward and keep our jobs, and eventually be better for it because that is what we do as a society.  Happy coding!

HOW TO: Use Await In Windows 8 Style Metro Coding

With the release of the new Visual Studio 11, and Microsoft 8, comes a new display and coding style targeting Metro. Metro is a display system that was modeled after a Swiss system of subway trains that allowed users to interact and purchase their tickets quickly and efficiently. A new very exciting keyword is being presented with the demos that are up called Await. What this keyword allows us to do is execute an asynchronous function or subroutine and move on with our code. This option is available very easily and does not require any timers or threading to handle any complex processes.
Here is a great example of how to use Await while reading a feed from a blog.

VB.NET

Private Async Function GetFeedAsync(FeedUriString As String) As Task
' Imports Windows.Web.Syndication
Dim Client As New SyndicationClient
Dim FeedUri As New Uri(FeedUriString)
Try
Dim Feed As SyndicationFeed = Await Client.RetrieveFeedAsync(FeedUri)
Dim FeedData As New FeedData
FeedData.Title = Feed.Title.Text

For Each Item As SyndicationItem In Feed.Items
Dim FeedItem As New FeedItem
FeedItem.Title = Item.Title.Text
FeedItem.PubDate = Item.PublishedDate.DateTime
FeedItem.Author = Item.Authors(0).Name.ToString()

If Feed.SourceFormat = SyndicationFormat.Atom10 Then
FeedItem.Content = Item.Content.Text
ElseIf Feed.SourceFormat = SyndicationFormat.Rss20 Then
FeedItem.Content = Item.Summary.Text
End If

FeedData.Items.Add(FeedItem)
Next

Me.DataContext = FeedData
ItemListView.SelectedIndex = 0
Catch Ex As Exception
' Log Error.
TitleText.Text = Ex.Message
End TryEnd Function

C#

private async Task GetFeedAsync(string feedUriString){
// using Windows.Web.Syndication;
SyndicationClient client = new SyndicationClient();
Uri feedUri = new Uri(feedUriString);

try {
SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
FeedData feedData = new FeedData();
feedData.Title = feed.Title.Text;

foreach (SyndicationItem item in feed.Items)
{
FeedItem feedItem = new FeedItem();
feedItem.Title = item.Title.Text;
feedItem.PubDate = item.PublishedDate.DateTime;
feedItem.Author = item.Authors[0].Name.ToString();
if (feed.SourceFormat == SyndicationFormat.Atom10)
{
feedItem.Content = item.Content.Text;
}
else if (feed.SourceFormat == SyndicationFormat.Rss20)
{
feedItem.Content = item.Summary.Text;
}
feedData.Items.Add(feedItem);
}
this.DataContext = feedData;
ItemListView.SelectedIndex = 0;
}
catch (Exception ex)
{
// Log Error.
TitleText.Text = ex.Message;
}
}