Bug fix: WPF4 project template for #MVVMLight V3

Ironically, my last release of MVVM Light V3 was about fixing bugs in templates and making them better. In the process however, seems that I introduced a regression bug in the WPF4 project templates. Yep shit happens.

How do I know if I have the bug?

Check the Programs and Features control panel, and look for MVVM Light. If the “Version” column shows 3.0.2.19, you have the bug. If it shows anything higher, you don’t. For instance, the new version with the bug correction is 3.0.3.19. Also, any version 4.*.*.* does not have this bug.

Alternatively, simply try to create a new WPF4 MVVM Light application in Studio. If you see the following warning, you have the bug.

Upgrading

To fix the bug, simply download V3.0.3.19 from Codeplex and install. You don’t need to uninstall the previous version.

What’s next?

I am working hard on V4 and have some nice improvements coming up. Many people have asked me when the “beta” will come out of MVVM Light, and the answer is “soon”. In the coming few days, I will publish a temporary release that corrects a few memory leaks, notably in the Messenger and in the RelayCommand. This will give expert users time to test and report issues. Then I still have a couple of fixes and I will release a release candidate. I won’t add any new feature after the RC, but will merely fix bugs if people find some. Once the RC is deemed stable, I will release V4 and take a deep breath!

And yes, there will be a V5 Smile

Happy coding,
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

New MVVM Light templates with bug fixes

The current version of MVVM Light had a couple of issues in the project templates. The most annoying one was causing a problem when creating new projects: The GUIDs used to uniquely identify the project were in fact not re-generated properly every time, and we ended up with the same GUID in every new project. The symptoms are the following: If you side-load an MVVM Light application, and then side-load another one, you will see that the first one is overwritten. Note however that this is only an issue when side-loading applications: The GUIDs are properly re-generated and overwritten by Microsoft during the app approval process.

This was not really an issue with WPF and Silverlight applications (which is why the bug was never found until now), however the Windows Phone uses these GUIDs to check if the application is already installed on the Windows Phone device or not.

I also took this occasion to update the templates with some information in the AssemblyInfo.cs, so that should make it even easier to fill the assembly information.

I just published a new MSI that corrects the issue. You can install the new MSI on top of the existing one. As usual, there is an MSI for MVVM Light V3 and one for MVVM Light V4 beta.

Fixing the issue in existing applications

If you encounter this issue in existing application, you can use the following steps to correct it. Note that I recommend you to follow these steps for every MVVM Light application.

  • Start the GUID generator installed with Visual Studio (open the Start menu and type GUID to find it).
  • In the GUID generator, select the Registry Format.
  • Press the New GUID button and then the Copy button.
2011010201
  • Open the CSPROJ file in Notepad (or any text editor).
  • Locate the <ProjectGuid> attribute.
  • Select its content and paste the GUID you previously copied.

For Windows Phone projects only, in addition:

  • In the GUID generator, press the New GUID button and then the Copy button.
  • Open the file WMAppManifest.xml (in the Properties folder).
  • Find the ProductID attribute and replace its content with the GUID you previously copied.

Projects exposed to COM

Some project also have a GUID in the AssemblyInfo.cs. Open this file in Visual Studio or in Notepad and check if you can see a GUID there. If there is one, copy a new GUID from the GUID generator and replace the old one with the one you just copied. Be careful to remove the opening ‘{‘ and closing ‘}’.

That’s it

Apologies for this bug, and thanks to everyone who reported it and helped make MVVM Light better.

Cheers,
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Quick travel tip: charging USB devices from the Samsung Slate 7

For those of you who have the Samsung Slate 7 that Microsoft gave at Build (or that you purchase yourself!), and who are travelling: I hate to take chargers for all my gadgets, especially since my Windows Phone, my Bluetooth stereo headset and my Kindle (amongst others) all use micro-USB to charge. So I just take a couple of micro USB cables and I can charge my devices from the PC.

However some laptops are cutting off power from the USB ports when they go to sleep. I thought it was the case with the Samsung Slate 7 too (the plugged-in phone will stop charging if you make the slate sleep). However I found out that if you unplug and then re-plug the USB cable, then the charging resumes and you can charge the whole night as needed Smile

This is a convenient travel tip, and maybe will be useful to some travellers on those Christmas and New Year holidays. I take the occasion to wish all my readers a happy Christmas time and hope that you can all enjoy a bit of rest!

Cheers,
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

MVVM Light installers and Nuget (including Silverlight 5) #mvvmlight

I just pushed two big updates to MVVM Light setup components.

MSI installers with Silverlight 5 support

The MSI installers are available on Codeplex. The current version supports Silverlight 3, Silverlight 4, Silverlight 5 (new), WPF 3.5 SP1, WPF 4, Windows Phone 7.0 and Windows Phone 7.1. The installer for V3 is available, as well as the one for V4 beta.

NuGet support including Silverlight 5

I also pushed a new version of the NuGet packages which includes Silverlight 5. To install MVVM Light into an existing application with the help of the NuGet package manager in Visual Studio, check the instructions.

If you look for “mvvmlight” on NuGet, you will find four packages:

  • MVVM Light: The whole package, libraries + ViewModelLocator + MainViewModel. Installing this also modifies App.xaml to install the ViewModelLocator. This package is for V3 of MVVM Light!
  • MVVM Light libraries only: Installs only the DLLs and references them. This package is for V3 of MVVM Light!
  • MVVM Light [Preview]: This is the whole package too, but for V4 beta.
  • MVVM Light libraries only [Preview]: Just the DLLs, for V4 beta.

Update on V4’s availability

One of the most annoying issues in V3 is a memory leak that can appear in the Messenger component in certain circumstances. I will post details in due time, but there is indeed a risk that an instance is not garbage collected if it is registered with the Messenger with a non-static method, and if the developer omits to unregister the instance before deleting it.

Because of the promise of a “weak” registration, I really want to solve this issue. Currently, I am able to completely solve it in WPF, and to solve it in most cases in Silverlight (including Windows Phone). There is still one special case in Silverlight where a memory leak may remain, and I am currently working on handling this. I am not sure that there is a solution for this last scenario, but there are other alternatives that it is not a blocking issue anymore.

Once this fix is fully tested, I still have a few things I would like to add in V4. However I am also aware that we have been in beta (and alpha) for quite some time already, and it is very possible that I procrastinate some of these features into V5.

Happy coding!
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

MVVM Light for Silverlight 5 is on Codeplex #mvvmlight

Here we go! After the Microsoft team released version 5 of Silverlight yesterday, MVVM Light is available for this version of the framework too. I did not create the installer yet (that will take a few more days), but you can download the source code and build it yourself easily.

With this latest release, this puts the number of supported frameworks to 8: .NET 3.5 SP1, .NET 4, Silverlight 3, Silverlight 4, Silverlight 5, Windows Phone 7.0, Windows Phone 7.1 and Windows 8 (preview).

The MVVM Light family

Dropping Silverlight 3 and WP7.0?

That said, I am considering dropping old frameworks now for new development. So here is a chance to make yourself heard, tell me if you think that it is OK to drop Silverlight 3 and/or Windows Phone 7.0 and to concentrate on the 6 other supported frameworks:

Thanks and happy coding!
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Silverlight 5 is released!

Microsoft just released the version 5 of Silverlight! It’s a great news and I really want to congratulate the whole team on this impressive collective effort. The official announcement is on the Silverlight team blog!

The purpose of this article is not to be exhaustive about the list of features (there have been, and will be, many more very detailed articles such as this series on the Silverlight blog) but rather to explain why this version in particular makes me happy to be a Silverlight developer (features listed in no particular order!).

3D!

One thing is making me really happy and excited: the 3D integration. It is now possible to include and manipulate 3D models within a Silverlight application. This model is very similar to what XNA offers, which means that existing XNA developers will feel at home very fast with this new platform. It also means that existing 3D models can quite easily be run in Silverlight 3D. I am sure we all have in mind the pretty amazing demo with Scott Gu’s avatar during the Silverlight 5 firestarter (jump to 51:11).

I am really happy to have 3D integration in Silverlight now, because I have been working for the past few weeks on a new application for Kinect for Windows involving a 3D human avatar integrated in a Windows Presentation Foundation. The integration is completely seamless, and it looks like the avatar is completely part of the rest of the application. However, the rest of the application is WPF, with all the XAML, binding and MVVM goodness that it brings. This kind of seamless integration is now also possible in Silverlight, and that opens the door to a lot of pretty cool applications and a new kind of user experience.

In-browser trusted applications

We all know (or heard of) the Out-Of-Browser (OOB) application model which allows Silverlight to run outside of a web browser, just like a Windows application in its own windows, with its own shortcut, etc. There is also an elevated trust model for OOB, declared at build time, which allows such applications to perform tasks that are usually not allowed (such as saving or reading files from certain locations on the computer, run in full-screen with full keyboard support (ideal for kiosk applications!), host HTML pages within the Silverlight application, etc.

These features were already available in Silverlight 4, however in Silverlight 5 they are also possible inside the web browser. This makes the delivery of such applications a little easier, since the user does not have to “install” them and deal with a shorcut.

Trickplay

This feature allows to play video at various speeds, and even includes pitch correction to avoid that the speaker sounds like a chipmunk! This is especially useful when watching conference sessions: watch a whole 60 minute session in 30 minutes, and use the rest of the hour to be with your family instead Smile

Breakpoints in bindings

This one is pretty cool: Who has never had to debug a binding, because the binding expression had a typo, or the value was not what you expected? it was pretty cumbersome before! Well with Silverlight 5, you can set a breakpoint right in the XAML binding expression, and the debugger will break and allow you to inspect the expression!.

Performance, profiling

A lot of work has been put into performance too, and a new set of tools helps to profile the application and identify critical areas that need perf tuning.

Pinvoke

This is like COM on steroid: This allows your Silverlight application to access pretty much any of the Win32 APIs directly from within your app. There are even ways to listen to Win32 messages, for example to be notified when a new USB drive is inserted (this is only an example!). There is a good article on pinvoke by Alexandra Rusina (one of Silverlight’s PMs) here.

Note that pinvoke only works with elevated permissions, which really makes sense (I wouldn’t want any script kiddy to be able to format my hard drives without saying “OK” first)!!.

And more…

There are a lot of other improvements, notably useful when you use the MVVM pattern in Silverlight. For example, the ability to search for an Ancestor in a RelativeSource binding (something we had since the beginning in WPF, and because it was missing here led to some cruel workarounds in some applications in Silverlight…) is a good example of these apparently small changes, but that will mean a lot when you do need them.

With version 5, we have a super mature version of the framework!

What about Mac? What about other browsers? What about delays? What about Maryjo?

As usual it is interesting to witness the drama around the (perceived) delay in the delivery of this massive new version. It is important however to remember that there had not been any official announcement about a delivery date (the only thing we had heard was Scott Guthrie – who is not in charge of this product anymore by the way - talk about “end of November”). With a delivery in the first half of December, and considering that much time has been spent on last minute bugs, making this version as stable as can be, and (again) considering the massive additions to this new version, I say kudos to the team!

Edit: Maryjo felt insulted and I am a nice guy, so let me rework that paragraph a bit. Yeah I went too far and personal, so hopefully this is better.

Maryjo Foley, who seems to be reporting and speculating on a lot of bad news these days, reported that Mac OS would not be supported for Silverlight 5, and even worse that only Internet Explorer would be supported on Windows.

Side note: She actually reported that “One of my contacts said he believed that the final version of Silverlight 5 may only work with Internet Explorer on Windows and won’t work on Mac OS platforms or with other browsers at all. (Silverlight 4 supports Windows and Mac OS X and the IE, Chrome and Safari browsers.)”. Notice the lack of named reference, the “he believed” and the “may work”.

It’s a good example of why we should take this kind of “journalism” with a grain of salt. We are very rational people, fond of science and technology, and yet we seem sometimes to act like schoolgirls when someone writes something on the web. At this point, I think it is good to remember that Maryjo often reports hearsay and rumors. I don’t mean that she is always wrong, not at all, and in fact I do read her column with interest. But I always take it with a (large) grain of salt, and I remember that until a product is released, we don’t know what it will support. Everything else, really, is conjectures. A good thing to remember while Windows 8 is in preparation!

Side note again: It is very painful to insiders to read this kind of articles (if you can call it that) while we knew very well that it was completely wrong. Unfortunately, the non-disclosure agreement that binds us to Microsoft prevents us from correcting assertions like this, and we had to sit down and watch. This is very unfortunate and painful. I really hope that people learn, some day, to be reasonable when it comes to technology (but I am not holding my breath).

To be clear: the list of supported web browsers and operating systems did not change. It is available at http://www.microsoft.com/silverlight/what-is-silverlight/.

Some restrictions

There are a few restrictions around the 3D rendering, for security reasons. The best summary I found so far is on David Catuhe’s blog. Security restrictions are always annoying but the alternative is letting unsafe code run on the user’s computer, and we all know how Microsoft handled that in the past (ActiveX anyone?) so I guess that we need to accept that they err on the side of security this time. (Edit: updated on 12/10/2011).

Also, like previously, COM access does not work on Mac OSX and as I mentioned above, p/invoke is also only available on Windows. Both these features require elevated permissions by the way.

What about MVVM Light?

MVVM Light will of course support Silverlight 5, and I will release a version soon. I just need a little more time running my tests and making sure that everything is working as expected. Stay tuned to this blog for an announcement about the release of MVVM Light for Silverlight 5!

A few additional updates

Well there was a nice storm on Twitter, and within the noise I managed to grab a few useful facts.

First, the Blend preview for Silverlight 5 is available here. I did not verify that it works with Silverlight 5 RTM, but I think it should.

Then, Silverlight 5 will be supported until December 2021. That’s 10 years of support.

The offline documentation can also be downloaded.

Finally there was a lot of passionate discussions on Twitter tonight. I think it was especially interesting to confront the view of tech journalists versus MVPs vs developers. Bottom line is that there is a lot of passion around tech these days. I personally think it is too much passion, but some disagree and I think we will have to live with that for years to come…

Cheers,
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

MVVM Light template and WCF services (or any ASP.NET application for that matter)

I was recently made aware of a couple of people having issues with WCF services (or ASP.NET applications) when using the MVVM Light project template for Silverlight. There is a blog post and a StackOverflow question, so what exactly is happening there?

Well in fact it is pretty simple when you know how Silverlight connects to web services. Due to the security model of Silverlight, the application cannot connect to a web site if it is not originating of this very website. In laymen’s terms, it means that the application can only connect to a web server if it also comes from the same webserver. For example, if the Silverlight application is served by http://www.galasoft.com, it won’t be able to connect to, say, http://www.cnn.com without getting an exception. We talk about cross-domain access restrictions.

Of course there are ways around that, for instance a website can specifically give access to Silverlight applications through a configuration file.

In the case that concerns us, it is exactly what is happening. You see, the MVVM Light Silverlight project template creates a Silverlight application without an ASP.NET host. I didn’t add one because I didn’t want to complicate the template too much. And also, to be honest, because adding a web project is super easy, but of course only if you know how to do, and this is exactly what we will do here!

Creating the application

The steps to create the application and the WCF service are as follows:

  • Create the MVVM Light application using the MVVM Light project template for Silverlight.
  • Right click on the solution in the Solution Explorer and select "Add, New Project from the context menu.
  • From the WCF category, select a WCF Service Application and create it.
  • Build the application.
  • Right click on the MVVM Light project and select Add Service Reference from the context menu.
  • In the Add Service Reference dialog, click on Discover.
  • Make sure that the found service is the one you want to connect to, and click on OK.
  • In the MVVM Light application, open the file Model/DataService.cs and modify the code as follows:
public class DataService : IDataService
{
    public void GetData(Action<DataItem, Exception> callback)
    {
        var client = new ServiceReference1.Service1Client();
        client.GetDataCompleted += ClientGetDataCompleted;

        client.GetDataAsync(1234, callback);
    }

    void ClientGetDataCompleted(
        object sender, 
        ServiceReference1.GetDataCompletedEventArgs e)
    {
        var callback = e.UserState as Action<DataItem, Exception>;

        if (callback == null)
        {
            return;
        }

        if (e.Error != null)
        {
            callback(null, e.Error);
        }

        callback(new DataItem(e.Result), null);
    }
}

This code uses an asynchronous service call pattern where the callback (a reference to a method passed as Action by the caller) is saved in the service call. Then when the asychronous call returns (in the Completed event), the callback is retrieved from the UserState. If an error occurred, the callback can be used to pass this error to the caller. Otherwise, a new DataItem class is created and passed to the called.

Details about this pattern can be found in my talks Understanding the MVVM pattern and Deep Dive MVVM.

So why doesn’t it work?

If you run the application now (making sure that the MVVM Light project is selected as Startup Project), you will first see a warning dialog and then an exception. What happened?

What happened here is exactly the cross-domain issue I mentioned: The Silverlight application is not explicitly hosted into a web application, so Visual Studio is using an auto-generated HTML page instead, and running it from the embedded web server (“Cassini”). In fact, unless you explicitly specified otherwise, the test page is run in “file mode” instead of HTTP mode. The URI in the web browser window starts with C:\ for instance, instead of http://.

In those conditions, the access to the WCF service is (justly) denied, and you get a security exception.

Correcting the error

In order to correct the error, you can either add a cross-domain policy file to your WCF application, or host the Silverlight application in the same web project as the WCF service. Let’s do that now:

  • Right click on the WCF Service application in the Solution Explorer, and select Properties from the context menu.
  • On the left, select the Silverlight Applications tab.
  • Click on Add.
  • Select Use an existing Silverlight project in the solution and make sure that your MVVM Light application is selected in the combo box.
  • Make sure that Add a test page that references the control is checked, as well as Enable Silverlight debugging.
  • Press Add.

This creates two new files in your WCF Service application: One is suffixed TestPage.html and the other is suffixed TestPage.aspx. We typically don’t need the ASPX one so you can safely delete it.

  • Right click on the WCF Service application and select Set as StartUp Project from the context menu.
  • Right click about the HTML test page and select Set as Start Page from the context menu.

By doing this, we force Visual Studio to serve the HTML page and the Silverlight application from the same URL as the WCF Service, and to serve it as HTTP. This is possible because a WCF Service application is nothing else than an ASP.NET web server running WCF. So the same web server can deliver HTML, Silverlight and of course WCF.

If you run the application now, you will see the following result:

Note that the warning shown earlier will still appear, but it is really just a warning, and you can safely turn it off. Just remember the cross-domain restriction when you publish your Silverlight application to another web server!

Success, we hit the WCF service and returned with a valid result! In fact, you can verify by placing breakpoints in the DataService.GetData method on the client, and in the Service1.GetData method on the server. Then press F5 to run the application in Debug mode and notice how you can easily debug both the client and the server at the same time.

What about the opposite way?

It is also possible to add a new MVVM Light application to an existing WCF Service application with the following steps (I am going a bit faster now, I am sure you will get it easily):

  • Open the existing WCF Service application.
  • Right click on the Solution and select Add New Project.
  • Select the MVVM Light project template for Silverlight and add a new project.
  • Build the application.
  • Just like before, add a Service Reference to the Silverlight application.
  • Again, just like before, add the Silverlight application to the WCF Service application (WCF Project Properties, Silverlight Applications, Add…).

Summary

Hopefully the confusion around this is cleared now. In summary:

  • Silverlight applications are restricted to access cross-domain web servers (unless explicitly authorized to do so).
  • The default MVVM Light application does not have an explicit host, so it runs off the default test page.
  • You can however easily add the MVVM Light application to the WCF Service application and then run it and debug it.

Note that the steps above can be used to add an MVVM Light application (or any Silverlight application) to any ASP.NET application, be it WCF Service application, ASP.NET MVC application or “classic” ASP.NET application.

Happy coding!
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Three years at IdentityMine–and more to come!

Logotype-pink

Today is the first day of my fourth year at IdentityMine. I can hardly believe how fast it went, and how exciting the trip has been so far. In the past three years, I have had the chance to work on exciting technologies like Windows Presentation Foundation (which is still very much active, and even more exciting since we now have the possibility to add Kinect interactions to any WPF application!), Silverlight, Windows Phone 7 (for which we have a lot of work right now), Microsoft Surface (for which we are close partners from Microsoft, both for version 1 and for the upcoming version 2 which is even more exciting thanks to the new form factor, improved resolution, etc), Kinect (do I even need to explain why this is exciting?) and more.

Right now, I am working on a Kinect for Windows project (which also includes 3D models) and involved at various degrees into a few other projects that I cannot talk about yet. We are also starting to gather ideas around real life Windows 8 applications, where we can leverage the Metro design, the mobility, multitouch, etc. In fact what is making me super happy in the moment, maybe even more than the momentum gained by Kinect in the living room, is the interest that it gets in the workplace. Imagine situations where people have dirty hands, or wet fingers; immediately touch (as well as the classic mouse/keyboard combination) become a challenge. With Kinect, we have a chance to change all this and to introduce a new user experience in locations where it can make a huge difference in people’s everyday life.

Update: I just found this video about Microsoft Surface 2 which illustrates so well the great times that we are living, and how certain technologies can make life better. I just had to post it here too Smile

The excitement continues

I know I sound like a broken record, but man I love this job. It’s no secret that 2011 has seen ups and downs for rich client application developers, with the questions around mobile technologies, the melodrama around Windows 8 and Silverlight, and the general negativity of a few vocal individuals in our community, it’s fair to say that it was tough to keep a happy spirit.

Now however I feel that we are somehow past this hurdle. Sure the future is still uncertain (it’s, like, the definition of “future” Winking smile) but it seems that our skills are going to allow us to do awesome stuff in the future, just like we did in the past. Windows Phone market share is rising, the Nokia partnership seems to be successful especially in terms of the marketing skills that the Nokia team is bringing (now THAT’S how you sell a phone!), Windows 8 has XAML/C#, we developers have a number of reasons to rejoice or at least to consider 2012 with a positive attitude.

An awesome team

What I love the most at IdentityMine is how involved our creative team is in the development process. I feel that they are my first clients, the ones I need to please before we ship the application to the “real clients”, the ones who pay for it. Smile No compromises here, and thanks to XAML and Expression Blend we really don’t have to ever tell them “I cannot do it”. This is a great feeling for a developer, and I think we too often forget how things were before XAML, when we had to compromise all the time instead of implementing the creative team’s vision.

The rest of the team is awesome too. The developers are super talented (you should see some of the magic these guys are doing…) and they really understand the value of UX and design. Our PMs are doing what I had always dreamed about: they facilitate our work instead of slowing us down with administrative demands. And the execs are taking our inputs and caring for our opinion regarding strategies.

So now is almost the time to get ready for 2012 (well we do have a few projects to finish first), and I couldn’t be happier to spend it at IdentityMine. Thanks guys for the love! Smile

Cheers,

Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Steve Jobs, the legacy

Today is a weird day. I just got the news, as I woke up, that Steve Jobs passed away last night. This news affected me more than I thought it would. I felt the need to write about these emotions, and about my history with Apple. This is probably more for myself than for the reader, so feel free to skip ahead if you don’t like this, but it felt appropriate to keep a few thoughts at this time.

I first used a computer at pre-university, probably when I was 15. It was an Apple Macintosh SE. Before that relatively “old” age, I had never touched a computer. This is rather unusual in our geeky community, but yeah as a kid I was not a geek. Or rather, I definitely was a geek, but not that kind of geek. I was rather in books all the time, and I had a vivid fantasy world, but I didn’t really touch or use technology much at the time. The Mac SE was pretty cool, mostly because everything was packed neatly together, and it was easy to carry around. It’s on this machine that I wrote my first code, and played my first game. I couldn’t tell you anymore what the name of the game was (I was really not too much into it) but I remember it was a quest game, happening in a fantasy world, and even though it was in black and white, it was enough to fuel the fantasy world I was living in. It is also at the time that I discovered fonts. I remember putting together crazy titles and texts, using various fonts and all kind of 3D effects, and being pretty fascinated by this. At the time I was very interested by logos and was drawing some by hand. I was considering becoming a graphics designer, and suddenly using a computer to do that was pretty fascinating. It was also kind of frustrating, because the attention to detail I had put in hand drawing these logos was suddenly not really necessary anymore. Anyone could come up with cool wording, using crazy font.

It’s also on this machine that I first wrote code. I can’t say I cared for it much, it was rather boring (we were using Logo) but I remember being excited the first time I managed to draw a circle on the screen. Again, I was really not very interested by technology at the time… though it is also at that time that I purchased my first PDA, a Casio “clamshell” design which couldn’t be synched with a computer, but on which I enthusiastically typed all my contacts, addresses, took notes, etc. It was the first in a very long line of PDAs (including pretty much all Palm devices) that culminated in today’s Windows Phone 7 that I use all the time.

An Apple fanboi

Later when I graduated, and considered going to engineer school, it became obvious that we needed a computer. My dad had, at the time, purchased a second hand PC from a colleague. It was running DOS only, and my first move when we got it home was to “clean up everything”. By that, I mean that I went ahead and deleted all the files I could find on it, thinking that it was old junk left by the previous owner. In the process I wiped out the whole OS, and needless to say, the computer didn’t really agree to start later. We had to call the guy who sold it to us, and he reinstalled it… Yeah that was not a great user experience. When we talked about buying a better computer, I pushed my parents to buy a Mac. It just seemed the right choice. At engineer school, I met a good friend who was a Mac fanatic, and I quickly became one too. The Mac we bought was an LCII, one of the low end models. I literally had no idea what I was buying at the time, and I didn’t really care. Quickly however I was spending hours on it (before you laugh, I *did* have a girlfriend at the time though Winking smile).

My friend Pascal was my dealer for pirated applications (installing an application for the Mac was as easy as copying it to the HDD and running it). At the time, my thinking was: I am broke now because I am a student, so I will just use these applications now because I need to learn them. Later when I make a living, I will always use legal applications – and I am proud to say that I do, I never used pirated applications anymore since I started earning money. Interestingly, I was really not into games at all. I used the Flight Simulator (I was a private pilot by then) but that was it, the rest was really databases (I loved to organize my items, books, videos, pictures, music in lists), some light coding, drawing and writing.

I was not all the time on the computer though. First, as I mentioned, I was in a relationship and we all know how time consuming that can be Winking smile Then, I was (and still am, although I have less time for it) a book worm. And I loved calligraphy, drawing, etc. So really not your typical computer geek. But I was, definitely, an Apple fanboi, even though we were running a low end model.

Being different

When I graduated, I did my whole thesis on the Apple. That included simulation (using Matlab), typing and typing and some typing, drawing schematics, etc. The thesis is a huge work that took us months, and the irony is that back then people were scowling at me for using a Mac. We were the misfits of the computer age. Everyone was saying how bad the Mac was, how much better a PC with Windows was, but we didn’t care. I actually enjoyed being and thinking different.

That is actually pretty funny and weird. I guess I never felt comfortable using the same stuff as everyone else (and in fact it is but one of the symptoms of my misanthropy). This continues today, with me rooting and coding and being an avid user of one of the least used mobile OS on the market (Windows Phone) when it would be just so much easier to do what everyone else does, and go with iPhone or Android. But the mere thought of that fills me with dread. It’s a sickness, really. I wonder what will happen when Windows Phone gets the popularity it deserves… will I move to iOS then? Probably not, but I guess I will just use the next newest thing that everyone scowls at Winking smile

The weaning

Everything has an end, and for me the end of the Apple fanboism came when I married. At the time, I was running a PC and a Mac at home, and it quickly became obvious that it was too much. I was doing most of my work on the PC, so we sold the Mac. I never really looked back. In retrospect it is interesting that most of my time as an Apple fan was pretty much at the same time that Jobs was out of Apple (1985 – 1996). It is not really surprising though, because I never really liked him. OK let’s face it, I didn’t like him at all as a person. And after he came back, I started to really dislike Apple as a firm. It bothers me that they are using legal actions to kill innovation in other firms. It bothers me that they are so secretive and paranoid about everything, that they became in fact the Big Brother they were criticizing in 1984. It bothers me that so many people using Apple products do so in a religious fashion, and are using proselytism to convince others to do so. It bothers me that being an Apple user is not about thinking different anymore, but about doing like the masses.

That sucked, because I really liked their products. But what can I say, I couldn’t see myself giving money to a firm I disliked. So I just stopped using Apple products, and never climbed on iOS, even though I of course use these devices from time to time for professional reasons. Then when .NET came out, and I started using it professionally, I also discovered a division within Microsoft (the DevDiv) that had an openness, a passion and a vision that were very appealing for me. I felt welcomed in that community, and this is when I turned, from an Apple fan, into a Microsoft enthusiast. I can’t say I am as much a fanboi for Microsoft than I was for Apple though, mostly because I grew older I guess, and more rational about all that tech stuff Winking smile. I am very aware of Microsoft’s shortcomings in many areas, but at the same time their technology and their UX vision appeals to me more than any other at this time. So I went from an Apple fanboi to a Microsoft enthusiast.

The legacy

I do however have a lot of respect for what Steve Jobs achieved, and his vision as a creator. People like Steve Jobs and Bill Gates changed the world, and their legacy pays for my kid’s food, education, clothes, for my house, for everything I have. Most importantly, they give me a (professional) purpose in life: Making the user experience better. Enabling everyone (not just us geeks) to use technology to make their own life easier and better. This is what I want to do with my life, and thanks to people like Steve Jobs and Bill Gates, this is what I can do.

In fact, I think that the reason why I am so affected but Steve Jobs’ death today is this: I always wanted to be an artist. Thanks to Jobs’ legacy, people like us who spend their life thinking about and working in user experience are not just geeks, not just engineers, not just technicians. We are also artists, and this is in great part thanks to Steve Jobs.

PS: This song and video are taken from my favorite movie ever: Itinéraire d'un enfant gâté. The actor is Jean-Paul Belmondo and the singer is Nicole Croisille. It’s an amazing movie.

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

MVVM Light Toolkit for Windows 8 (preview) #mvvmlight #win8

I was very optimistic when I first saw Metro style apps coded in C# on Windows 8, because for the most part they are not much different than the well known XAML/C# pair on Silverlight or WPF. This led me to brag a bit about probably having a port of MVVM Light ready “in a few days”. Of course I didn’t take in account that I would have a great time the week after //build in Seattle, with fantastic weather and tons of friends to have dinner and conversations with. Needless to say, the few days turned out, in fact, to be a couple of weeks.

Nonetheless, I am proud and happy to announce the availability of MVVM Light Toolkit for Windows 8. Let’s be clear, this is a preview version. All the unit tests are green for the selected components (there are a couple of components not ported yet, see the section below titled “Missing components”). However, a green unit test does not quite mean that the tested component is completely safe to use, so please be careful with that material and send me your feedback if you find issues.

Installation

MVVM Light for Windows 8 is a side-by-side install with the standard MVVM Light V3 or V4 beta. Simply download and run the MSI from Codeplex. As usual, the last step of the installation performs a “/setup” of Visual Studio to actualize the project template cache, and unfortunately this last step can last very long. Please be patient and don’t cancel before the end! The installation process is very similar to that described on the MVVM Light installation page (except that there is no NuGet installer for VS11 yet).

Note however that if you uninstall MVVM Light V3/V4b, but still want to keep MVVM Light for Win8, you may have to repair MVVM Light for Win8. Simply run the installer again and select “Repair”.

Ported components

Almost all MVVM Light components are also available in the Windows 8 version. The ported components are:

  • ObservableObject including all ways to raise PropertyChanged.
  • ViewModelBase including all ways to raise PropertyChanged.
  • Messenger including all message types except DialogMessage (see below).
  • RelayCommand with and without parameter.
  • SimpleIoc which might well be the very first IOC container working on Windows 8.

File, New Project

I also created a Metro style version of the MVVM Light project template. To create a new MVVM Light-powered Metro Style application, follow the steps:

  • Select the menu File, New, Project.
  • In the New Project dialog, select the category Visual C# / Wndows Metro style and double click the MvvmLight (Win8) template.

The created application is a very simple MVVM application, very similar to the ones that get created in Silverlight, WPF or Windows Phone 7: it contains a model with IDataService, a dummy runtime implementation and a design time implementation. The ViewModelLocator is available and “wired” (using the SimpleIoc container) as well as a MainViewModel that is set as DataContext on the MainPage.

Missing components

  • Skins: There is a small change in the way that resource dictionaries are handled in Windows 8. I need to sort things out, so right now there is no “MainSkin.xaml” in the project template.
  • DialogMessage: This type is bugging me in V3/V4b because it is bringing the MessageBoxResult type into the ViewModel. I am looking at ways to make it better by converting the MessageBoxResult into a vanilla Boolean. In Windows 8, MessageBoxResult does not exist anymore (there is no MessageBox or popups of any kinds in Metro style apps). Consequently, the DialogMessage does not build, and I decided to just remove it for now. I will add it again when I refactor to the “vanilla” version.
  • EventToCommand: There are no Blend behaviors in Windows 8 yet (important word: yet). I am looking at ways to have behaviors on Windows 8 before Blend 5 for XAML gets released. Stay tuned.
  • DispatcherHelper: The Dispatcher object has changed quite a lot in Windows 8, and I am looking at ways to keep the DispatcherHelper compatible with previous versions of MVVM Light by wrapping these differences. It shouldn’t be a big deal, but I want to give myself a little time to get it right (hopefully).

Next steps

I intend to build a small sample application (very similar to the one I built for my MIX11 talk) to try the various components in real life conditions. This will of course be the topic of an upcoming blog post.

I encourage everyone to try these components in Windows 8 preview, and please don’t be shy with your feedback!

Cheers,
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Breaking change: Raising PropertyChanged with string.Empty in WinRT / Windows 8

In the developer preview of Windows 8, I just noticed a breaking change in the way that data bindings react to the PropertyChanged event.

First a bit of background: Often, objects that are databound to the UI are simple data objects (also called ViewModels) that implement the INotifyPropertyChanged interface. This interface is very simple and defines just one event, the PropertyChanged event, that needs to be raised by the ViewModel when one of its property changes. It is what makes the ViewModel “observable”. If a property of another object (typically a UI element) is data bound (through a Binding object, often set declaratively in XAML), then the value of the observing property will be synchronized to the value of the observable property.

Raising the PropertyChanged event requires an instance of the PropertyChangedEventArgs class, which takes a string as sole parameter of its constructor. The string to be passed is the name of the observable property.

Raising with string.Empty or null

In WPF and Silverlight, it is possible to raise the PropertyChanged event with an instance of the PropertyChangedEventArgs class constructed with string.Empty (or null) instead of an existing property’s name. When a PropertyChanged event is raised in this manner, the UI will re-query the value of each property of the ViewModel that is data bound to the UI. This is a convenient way to raise but one event and force the UI to update itself in response to cascading changes, for example. As such, this can be a good way to increase the performance of the application.

The breaking change in WinRT

However, while unit testing the version of MVVM Light for WinRT, I found out that raising the PropertyChanged event with an empty string or null does not update the bindings. I quickly coded a repro, and then coded the exact same code in Silverlight, and indeed the two applications do not react the same at all.

Hopefully this is only an oversight and this will be fixed in a future version.

Cheers,
Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Quick tip: Killing a Metro-style app in Windows 8

Metro-style apps are very similar to Windows Phone apps. They have a similar application model (for example they can be suspended, and when suspended they can be killed by the operating system if memory is needed), so they need to maintain state. Also, and that is the topic of this post, they cannot be ended by the user in a “normal” way, i.e. there is no File / Exit menu and no “X” button in the corner. Once started, the application remains in memory until the following happens:

  • The app is in suspended mode (not in the foreground) and the system needs to reclaim the RAM.
  • The advanced user starts the Task manager, locates the application and kills the process.

Note: Unfortunately I cannot illustrate this with a picture, because my Task Manager refuses to run more than 2 seconds for some unknown reason. Windows 8 is a preview release (TM).

However sometimes you need to kill a Metro style app, because Visual Studio will refuse to start a second instance if the first one is still running. You will get an error message like the following:

So should you use the task manager?

Well thankfully you don’t have to use the task manager (which is a blessing since, as I mentioned, mine keeps crashing all the time). Instead, just navigate to the application in question with Alt-Tab, and then press Alt-F4. This is a quick and easy way to euthanize your app and start a fresh new one in Studio later.

Update: The excellent and always vigilant Tim Heuer just told me that the Alt-F4 tip only applies to Windows 8 running with a developer license. No Alt-F4 for non coders, it seems Smile

Of course, pressing Alt-F4 requires you to have a real keyboard, since the on screen keyboard does not have any function key (nor the Alt key for that matter). But honestly, who writes code without a real keyboard anyway (I mean, except me when I am in bed and REALLY REALLY want to try something out).

Cheers,

Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Quick tip: Select the correct INotifyPropertyChanged in Windows 8 / WinRT

Microsoft loves MVVM and INotifyPropertyChanged so much that they included this very useful interface twice in the new WinRT framework. Unfortunately, only one of these is working correctly (and the other one is likely a bug, remnant from the past Winking smile)

When implementing INotifyPropertyChanged, make sure that you select the correct one! The one you want to use is into Windows.UI.Xaml.Data. The old one, the one you DON’T WANT is into System.ComponentModel (the same namespace it was in WPF and Silverlight). If you select the wrong one, the Bindings will not be updated and the UI will remain dead as a dead fish.

I mentioned before that Microsoft took the “once in a lifetime” opportunity (well, 5-10 years is a lifetime in the world of computers) to clean up and rearrange classes within the framework. This is one of the signs right here. As for the System.ComponentModel.INotifyPropertyChanged, I guess it will be removed in a later release of the WinRT framework.

Update: Indeed I was just told by the excellent and always vigilant Tim Heuer that this bug has already been fixed. I guess we will see the fix in the next release to developers of Windows 8.

Cheers,

Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Detecting design mode in Windows 8/WinRT

One of the very useful features of the MVVM Light toolkit is to help with the creation of design time data, in order to give something to see on the design surface (Expression Blend, Visual Studio designer). This is especially useful when designing list controls such as ListBox, ComboBox, etc. Without design time data, these controls will remain empty, and the designer will not see what he is working on. This can cost a lot of time and cause frustration.

Detecting design mode was always incompatible in WPF and in Silverlight.

  • In WPF, we use a rather complicated snippet:
var prop = DesignerProperties.IsInDesignModeProperty;
_isInDesignMode
    = (bool)DependencyPropertyDescriptor
                 .FromProperty(prop, typeof(FrameworkElement))
                 .Metadata.DefaultValue;
  • In Silverlight, there is a convenient property:
_isInDesignMode = DesignerProperties.IsInDesignTool;

 

_isInDesignMode 
    = Windows.ApplicationModel.DesignMode.DesignModeEnabled;

 

Abstracting the differences

These differences can make it difficult to share code between these environments. This is why the MVVM Light toolkit abstracts these and provides a convenient property on the ViewModelBase class:

(within a ViewModel deriving from ViewModelBase):

if (IsInDesignMode)
{
    // Create design time data
}
else
{
    // Create run time data
}

(within any class not deriving from ViewModelBase):

if (ViewModelBase.IsInDesignModeStatic)
{
    // Create design time data
}
else
{
    // Create run time data
}

Happy coding!

Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Dealing with types in WinRT

Another quick tip: Most of the interaction with the System.Type class in Windows 8 is now done through the TypeInfo class. An instance of TypeInfo for a give type is retrieved using an extension method called GetTypeInfo(). Note that since this is an extension method, it will not be visible in Intellisense unless you add a reference to System.Reflection in the “using” section:

// Needed for the extension method
using System.Reflection;

(...)

var info = myType.GetTypeInfo();

// Was: string name = myType.Name
string name = info.Name;

// Was: Type[] interfaces = myType.GetInterfaces();
IEnumerable<Type> interfaces = info.ImplementedInterfaces;

// Was: bool check = myType.IsSubclassOf(anotherType);
bool check = anotherType.GetTypeInfo().IsAssignableFrom(info);

(etc...)

Note: IsSubclassOf and IsAssignableFrom do not have the exact same meaning, however in many cases it should be able to use IsAssignableFrom. Make sure to check the documentation to verify that this is indeed what you want!

Hopefully this is useful to WinRT coders out there!

Laurent

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati