Windows 8 Metro Tips and Tricks

Windows 8 Metro Style

It is important to know some key shortcats in order to be productive and efficient when working in Windows 8 specially in Metro style Mode. Since any Metro App does not have Exit option it is important to know how to return back or how to log off or turn off our PC.

Since there is no Exit command in Metro, applications cannot be exited in the traditional way. In fact every Metro style app has three states Active- when it is showed on screen, Suspended- when it is in background and Destroyed- when OS kill the process of your app. When other Windows 8 Metro app is launched, the previous application goes off the screen and becomes suspended. After about 5 seconds application goes to transient state. It is important to know that suspended apps are not removed from memory, but all their threads are suspended. On that way suspended application can be activated and showed on the Metro screen immediately. On the other hand suspended apps don’t consume energy or they consume energy in minimum amount. Suspended apps can be terminated of a low memory condition. This is the case when the application is relaunched as a new run. During relaunching it can be implemented so that the app can restore its state from persistent storage and appear to the user as if it has never been gone.

At the end of this blog post let’s review the shortcuts for some action in Windws 8 Metro:

  • winkey – switch between Desktop and Metro mode
  • winkey+L – Log off from the Window current session
  • winkey+F – Open Metro Search engine for searching different content: Apps, files, settings, etc
  • winkey+P – Change Monitors layout.
  • winkey+any – Starts searching for content.
  •  winkey+ESC – Back to Desktop mode (Windows 7++).
  • winkey+i –    Setting of Desktop, Power, Audio and Network.
  • winkey+o – Lock screen rotation.
  • winkey+d –  Whos Desktop mode (Windows 7++)
  • winkey+h –  Open the share charm
  • winkey+k –   Open the connect share charm
  • winkey+TAB – Toggles between opened apps
  • winkey+SPACE – Toggles input language and keyboard
  • winkey+c –   Open the “charms bar” (share, settings, shutdown)
  • Mouse RClick on App Tile – shows the App Bar with advanced option.
  • ALT+TAB – Switch between apps.
  • Press any key – Unlock screen
  • CTRL+SHIFT+ESC – force to close metro app, since there is no Exit option in app.

Yet another scientific work based on GPdotNET

University of Bihać will organize 8th Scientific Conference about Development and Revitalization of production (RIM 2011) this week. I am also on this conference with my work about Modeling Hardness of steel weld by genetic programming, which is based on my genetic programming tool GPdotNET. I am very proud to announce that this is my second work based on the GPdotNET. After my work about modeling and optimization of Drilling process by Evolutionary algorithms from 2007, this time it is about modeling steel weld. This work is introduction of my Master Thesis which is going to be out soon :).
The presentation will be at Saturday at 9:30. More abut the conference can be found at
Meet you there.

Consuming WCF in Windows 8 Metro style app

Asynchronous programming is introduced in a new version of programming languages (C++, C# and JavaScript) which are part of the WinRT and .NET. If you are programming in C# you can program asynchronous by using async and await keyword. In fact when you program with async and await you actually program as ordinary synchronous code. That’s the big thing about this type of programming model.
More information about C# asynchronous programming you can found in my previous posts.
Since we have asynchronous programming model in all languages calling service operations asynchrony is not relevant at all. We can just forget it and start writing code like synchronous. To see hot new pattern is reflected in WCF lets implement simple service and simple metro style app consumer.
Implementation of the WCF Simple Service:

  • Create new ASP.NET Empty Web App
  • Add new Item-> WCF Service
  • Name it as SimpleService.svc

Service Interface looks like the following implementation:

public interface ISimpleService
    [WebGet(UriTemplate="AllData",ResponseFormat= WebMessageFormat.Json)]
    List<string> GetSomeData();

Implement one operation in the service like the following code implementation:

public class SimpleService : ISimpleService
    public List<string> GetSomeData()
        List<string> lst = new List<string>();
        for (int i = 0; i < 10; i++)
            lst.Add(string.Format("Item number {0}", i + 1));
        return lst;

The mentioned operation returns list of string but between populating the collection we sleep the current thread for 0,5 second in order to simulate log running operation.

It is necessary to publish the WCF service on remote host, in order to consume it. I still dont know why WCF service cannot be consumed by Metro app on the localhost. After the service is published on remoter host, we are ready to create Metro style Consumer app.

  • Right click on solution item
  • Add New Project
  • Choose Application template from the Metro Style app
  • Name it WCFConsumer

  • Add service reference to C# Metro Stryle app.
  • Add the GridView and some other input controls (buttons, editbox , etc) that we can test application responsiveness. Add the following XAML code in MainPage.xaml:
<Grid x:Name="LayoutRoot" Background="#FF0C0C0C">
        <ColumnDefinition Width="151*"/>
        <ColumnDefinition Width="326*"/>
        <ColumnDefinition Width="207*"/>
        <RowDefinition Height="74*"/>
        <RowDefinition Height="185*"/>
        <RowDefinition Height="68*"/>
    <GridView x:Name="gridData" Grid.Column="1" Grid.Row="1" />
    <HyperlinkButton Content="HyperlinkButton"   Grid.Column="1" HorizontalAlignment="Left" Height="25" Margin="58,30,0,0" VerticalAlignment="Top" Width="126"/>
    <Button Content="Button" Grid.Column="1" HorizontalAlignment="Left" Height="40" Margin="69,8,0,0" Grid.Row="2" VerticalAlignment="Top" Width="182"/>
    <TextBox Grid.Column="2" HorizontalAlignment="Left" Height="27" Margin="21,79,0,0" Grid.Row="1" Text="TextBox" VerticalAlignment="Top" Width="161"/>
    <TextBox HorizontalAlignment="Left" Height="15" Margin="24,79,0,0" Grid.Row="1" Text="TextBox" VerticalAlignment="Top" Width="102"/>
    <Image Grid.ColumnSpan="2" Grid.Column="1" HorizontalAlignment="Left" Height="100" Margin="312,240,0,-272" Grid.Row="2" VerticalAlignment="Top" Width="100"/>

The picture below shows the example ot the mainPage.

  • Implement Loaded event in to MainPage.xaml and insert the following code.
private void UserControl_Loaded(object sender, RoutedEventArgs e)
        SimpleServiceNamespace.SimpleServiceClient client = new SimpleServiceNamespace.SimpleServiceClient();
        var servicedata = client.GetSomeDataAsync();
        gridData.ItemsSource = servicedata.Result;

Even if GetSomeDataAsync method is asynchronous we don’t implement callback because this operation is implemented based on the async and await C# keyword and no need to do that.
Just assign the result of the servicedata to the GridView.ItemsSource.
If we run the app, we can see that the data is loaded asynchronously and UI is not blocked. We can click on buttons, tipe some texts while data is loading. This is awesome and now we can think about application logic instead of callback service implementation. This programming pattern works not just for Metro style apps, in fact it works for all .NET 4.5 based applications.