Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / operating-systems / Windows / WinRT

WinRT: My First Impressions

5.00/5 (2 votes)
4 Mar 2014CPOL6 min read 15.5K  
My first impressions of WinRT

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

So I have just finished doing my 1st WinRT demo article (and yes, it is for an article for CodeProject), which I will have up soon. Coming from a place where I was working a lot with WPF, I thought it might be a good idea to capture some of my thoughts/current gripes when working with Win8/WinRT.

I have tried to be as pragmatic as possible, and view WinRT as a v1 thing, which will (hopefully) get better in time. That said there were certain things I just missed a lot. I think what I will do is just list some of the things I found lacking when I was doing my little demo app, and then I will talk about how I found the whole Win8/WinRT ecco system.

Some of the Issues that Bugged me

So here is a list of things that I found a bit odd/off, now that is not to say that these will not get fixed, but they still bugged me all the same.

XAML Issues

  • DependencyProperty system, looked far less able when compared to WPF
  • On more than 1 occasion, I found that my ComboBox ItemSource Binding must appear before SelectedItem Binding in XAML if you want SelectedItem to populate correctly from the ViewModel (this seemed to be a problem in 8.0 at least), also I believe I have seen this bug before in days of old in both WPF and SL
  • No binding in setters within Styles (even SL has this now in SL5). This one needs fixing like NOW. It's plain wrong, and the workaround sucks
  • RelativeSource binding is far less able when compared to WPF
  • Visibility is lacking “Hidden”, which is actually useful
  • No DependencyPropertyDescriptor
  • Can’t do BasedOn style that allows you to BasedOn default style (or maybe I just didn’t know how to do it)
  • No x:Static markup extension. This is extremely useful for binding to singleton instance (which I use for all my ValueConverters)
  • No x:Type markup extension
  • No custom markup extension
  • No DynamicResource markup extension
  • No VisualStateManager.GoToElementState(..)
  • I may be wrong on this, but it didn’t seem to be able to have nested VisualStates one for top level control, and then some for some inner control.
  • WebView is still 2nd class citizen, in certain scenarios it's still ALWAYS on top.
  • ListBox backgroundColor / BorderBrush do not work that well with Focus, you have to restyle either whole control or ListBoxItem (container) taking into account Focus VisualState (I think this is a pain, others probably disagree)

Decision Issues

  • No DatePicker control (ok it's coming in 8.1, but please what the heck, do people not need to amend/pick dates in Windows 8. This is plain lazy.)
  • No Triggers in Styles/DataTemplates. Follows the SL model of VisualState(s). In my opinion (and I am not alone here), Triggers are and ALWAYS will be more powerful than visual states. At least, give us both and let us use which model we prefer.
  • No Blend interactivity interactions. My God so we are now back in WPF v1 land where we have to right our own attached behaviors for everything. Practically, any XAML developer will have become accustomed to using the standard Blend interactions / behaviors. We want these back.

Plain Weird Issues

  • Enumerable.Range(2013,2023) plain doesn’t work. Try that and see what you get. It is very odd.
  • DateTime object is very limited compared to .NET version.

What was the Win8 Ecco System Like To Use

WinJS or C#

Now as I have stated I am predominately involved with WPF, I do however also do a fair amount of ASP .NET MVC / and MVC/MVVM client side JavaScript development (Knockout.js / Angular.js / BackBone.js). So what language did I pick when doing my Win8 article. For me, that was a no brainer, C#. To be honest, I find the whole idea of a bastardized version of JavaScript that will only run on Windows8.* completely alien. If you believe the press, it's plain JavaScript. Sure it is.

The other thing I just don’t see it as a very transferable skill (oddly XAML is, it's in WPF / SL and now WinRT). For example, if I used just WinJS every day, do you think that would be a transferable skill, cos I sure don’t. Let's say I was doing TypeScript or native JavaScript, would they be transferable skills, well, yes they would. C# on the other hand, is still very much in vogue if you ask me. So that 1st language choice hurdle was an easy one for me to make.

Others may strongly disagree, but that was just my take on it.

App Structure

I have to say I am not madly keen on the overall application structure. I mean have you seen how much boilerplate code you get in App.xaml.cs, here it is for a new project. That's nasty if you ask me:

C#
///
/// Provides application-specific behavior to supplement the default Application class.
///
sealed partial class App : Application
{
    ///
/// Initializes the singleton Application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    ///
    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
    }

    ///
/// Invoked when the application is launched normally by the end user.  Other entry points
    /// will be used when the application is launched to open a specific file, to display
    /// search results, and so forth.
    ///
    ///Details about the launch request and process.
    protected override async void OnLaunched(LaunchActivatedEventArgs args)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active

        if (rootFrame == null)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();
            //Associate the frame with a SuspensionManager key
            SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                // Restore the saved session state only when appropriate
                try
                {
                    await SuspensionManager.RestoreAsync();
                }
                catch (SuspensionManagerException)
                {
                    //Something went wrong restoring state.
                    //Assume there is no state and continue
                }
            }

            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }
        if (rootFrame.Content == null)
        {
            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            if (!rootFrame.Navigate(typeof(GroupedItemsPage), "AllGroups"))
            {
                throw new Exception("Failed to create initial page");
            }
        }
        // Ensure the current window is active
        Window.Current.Activate();
    }

    ///
/// Invoked when application execution is being suspended.  Application state is saved
    /// without knowing whether the application will be terminated or resumed with the contents
    /// of memory still intact.
    ///
    ///The source of the suspend request.
    ///Details about the suspend request.
    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        var deferral = e.SuspendingOperation.GetDeferral();
        await SuspensionManager.SaveAsync();
        deferral.Complete();
    }
}

Coming from other stuff like there is a lot less clutter in the main entry point.

The other thing I really didn’t like is the way you had to have this special ResourceDictionary called “StandardStyles.xaml“. If they truly are standard, what the hell are they doing in my app, and why aren’t they included in the framework. Also why are most of the styles in there commented out, and we have to uncomment them as we need them.

Magic Classes That Are Provided

I also didn’t like the fact that there are a bunch of classes provided which I have no idea whether I need them or not.

For example, if you create a new Grid application you get this:

  • Common
    • BindableBase
    • BooleanNegationConverter
    • BooleanToVisibilityConverter
    • LayoutAwarePage
    • RichTextColumns
    • SuspensionManager

Now I know what a value converter is, so they are ok, but don’t things like “LayoutAwarePage“ and “SuspensionManager” sound like framework issues to you? They sure do to me, again why are these classes in my codebase. Surely a LayoutAwarePage should be the defacto page for ANY WinRT application. You know we are supposed to think that the Surface is an iPad rival, yet last time I looked I could twist an iPad this way and that, and you can also do that with a Surface. So why isn’t the LayoutAwarePage the standard. By the same token, since there is a suspension type of lifecycle in WinRT, why is the SuspensionManager not in the class library.

Also what the heck is “RichTextColumns” do I need that, what does it do. Is it required for a GridView, and if so (yes, I’ll say it again) why isn’t it in the framework.

Ok, I could find out, but when I start a new app, I would much prefer to see a clean slate really.

Early Days But

To my mind, it just feels like it was rushed out the door, and feels very unpolished. Now I am a massive Microsoft fan boy, but I just felt let down by WinRT. As I say, I will still be putting out this WinRT article soon, but it will likely be my one and only for a while.

Anyway, those are just my thoughts, no one else's, many will likely disagree, which is fine.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)