Multithreading in Windows Phone 7 emulator: A bug

Multithreading is supported in Windows Phone 7 Silverlight applications, however the emulator has a bug (which I discovered and was confirmed to me by the dev lead of the emulator team): If you attempt to start a background thread in the MainPage constructor, the thread never starts. The reason is a problem with the emulator UI thread which doesn’t leave any time to the background thread to start. Thankfully there is a workaround (see code below). Also, the bug should be corrected in a future release, so it’s not a big deal, even though it is really confusing when you try to understand why the *%&^$£% thread is not &$%&%$£ starting (that was me in the plane the other day ;)

This code does not work:

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();

        SupportedOrientations = SupportedPageOrientation.Portrait
            | SupportedPageOrientation.Landscape;

        var counter = 0;

        ThreadPool.QueueUserWorkItem(o =>
        {
            while (true)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    textBlockListTitle.Text = (counter++).ToString();
                });
            }
        });
    }
}

This code does work:

public MainPage()
{
    InitializeComponent();

    SupportedOrientations = SupportedPageOrientation.Portrait
        | SupportedPageOrientation.Landscape;

    var counter = 0;

    ThreadPool.QueueUserWorkItem(o =>
    {
        while (true)
        {
            Dispatcher.BeginInvoke(() =>
            {
                textBlockListTitle.Text = (counter++).ToString();
            });

            // NOTICE THIS LINE!!!
            Thread.Sleep(0);
        }
    });
}

Note that even if the thread is started in a later event (for example Click of a Button), the behavior without the Thread.Sleep(0) is not good in the emulator. As of now, i would recommend always sleeping when starting a new thread.

Happy coding:

Laurent

 

Sample code for my #mix10 talk online

I just saw that the video for my MIX10 session is online already! Impressive work, MIX10 team. I also published the sample code on my web server, so here are the links:

It was a real pleasure and an amazing experience to have this talk and to get all the great feedback! Thanks all for coming, and as usual don’t hesitate to send your feedback!

Laurent

What’s new in MVVM Light V3

V3 of the MVVM Light Toolkit was released during MIX10, after quite a long alpha stage. This post lists the new features in MVVM Light V3.

Compatibility

MVVM Light Toolkit V3 can be installed for the following tools and framework versions:

  • Visual Studio 2008 SP1, Expression Blend 3
    • Windows Presentation Foundation 3.5 SP1
    • Silverlight 3
  • Visual Studio 2010 RC, Expression Blend 4 beta
    • Windows Presentation Foundation 3.5 SP1
    • Windows Presentation Foundation 4 RC
    • Silverlight 3
    • Silverlight 4 RC

For more information about installing the MVVM Light Toolkit V3, please visit this page. For cleaning up existing installation, see this page.

New in V3 RTM

The following features have been added after V3 alpha3:

Project template for the Windows Phone 7 series (Silverlight)

This new template allows you to create a new MVVM Light application in Visual Studio 2010 RC and to run it in the Windows Phone 7 series emulator. This template uses the Silverlight 3 version of the MVVM Light Toolkit V3. At this time, only the essentials features of the GalaSoft.MvvmLight.dll assembly are supported on the phone.

New in V3 alpha3

The following features have been added after V3 alpha2:

New logo

An awesome logo has been designed for MVVM Light by Philippe Schutz.

DispatcherHelper class (in GalaSoft.MvvmLight.Extras.dll)

This class is useful when you work on multi-threaded WPF or Silverlight applications.

Initializing: The DispatcherHelper class must be initialized in the UI thread. For example, you can initialize the class in a Silverlight application’s Application_Startup event handler, or in the WPF application’s static App constructor (in App.xaml).

// Initializing in Silverlight (in App.xaml)

private void Application_Startup(
    object sender,
    StartupEventArgs e)
{
    RootVisual = new MainPage();
    DispatcherHelper.Initialize();
}


// Initializing in WPF (in App.xaml)

static App()
{
    DispatcherHelper.Initialize();
}

Verifying if a property exists

The ViewModelBase.RaisePropertyChanged method now checks if a given property name exists on the ViewModel class, and throws an exception if that property cannot be found. This is useful to detect typos in a property name, for example during a refactoring. Note that the check is only done in DEBUG mode.

Replacing IDisposable with ICleanup

The IDisposable implementation in the ViewModelBase class has been marked obsolete. Instead, the ICleanup interface (and its Cleanup method) has been added. Implementing IDisposable in a ViewModel is still possible, but must be done explicitly. IDisposable in ViewModelBase was a bad practice, because it supposes that the ViewModel is garbage collected after Dispose is called. instead, the Cleanup method does not have such expectation.

The ViewModelLocator class (created when an MVVM Light project template is used in Visual Studio or Expression Blend) exposes a static Cleanup method, which should in turn call each ViewModel’s Cleanup method. The ViewModel is free to override the Cleanup method if local cleanup must be performed.

Passing EventArgs to command with EventToCommand

The EventToCommand class is used to bind any event to an ICommand (typically on the ViewModel). In this case, it can be useful to pass the event’s EventArgs parameter to the command in the ViewModel. For example, for the MouseEnter event, you can pass the MouseEventArgs to a RelayCommand<MouseEventArgs> as shown in the next listings.

Note: Bringing UI specific classes (such as EventArgs) into the ViewModel reduces the testability of the ViewModel, and thus should be used with care.

Setting EventToCommand and PassEventArgsToCommand:

<Grid x:Name="LayoutRoot">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseEnter">
            <cmd:EventToCommand Command="{Binding MyCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Grid>

Getting the EventArgs in the command

public RelayCommand<MouseEventArgs> MyCommand
{
    get;
    private set;
}

public MainViewModel()
{
    MyCommand = new RelayCommand<MouseEventArgs>(e =>
    {
        // e is of type MouseEventArgs
    });
}

Changes to templates

Various changes have been made to project templates and item templates to make them more compatible with Silverlight 4 and to improve their visibility in Visual Studio and Expression Blend.

Bug corrections

  • When a message is sent through the Messenger class using the method Messenger.Default.Send<T>(T message, object token), and the token is a simple value (for example int), the message was not sent correctly. This bug is now corrected.

New in V3

The following features have been added after V2.

Sending messages with callback

Certain classes have been added to the GalaSoft.MvvmLight.Messaging namespace, allowing sending a message and getting a callback from the recipient. These classes are:

  • NotificationMessageWithCallback: Base class for messages with callback.
  • NotificationMessageAction: A class with string notification, and a parameterless callback.
  • NotificationMessageAction<T>: A class with string notification, and a callback with a parameter of type T.

To send a message with callback, use the following code:

var message = new NotificationMessageAction<bool>(
    "Hello world",
    callbackMessage =>
    {
        // This is the callback code
        if (callbackMessage)
        {
            // ...
        }
    });

Messenger.Default.Send(message);

To register and receive a message with callback, use the following code:

Messenger.Default.Register<NotificationMessageAction<bool>>(
    this,
    message =>
    {
        // Do something
        
        // Execute the callback
        message.Execute(true);
    });

Messenger.Default can be overriden

The Messenger.Default property can also be replaced, for example for unit testing purposes, by using the Messenger.OverrideDefault method. All the public methods of the Messenger class have been made virtual, and can be overridden in the test messenger class.

Sending messages to interfaces

In V2, it was possible to deliver messages targeted to instances of a given class. in V3 it is still possible, but in addition you can deliver a message to instances that implement a certain interface. The message will not be delivered to other recipients.

Use the overload Messenger.Default.Send<TMessage, TTarget>(TMessage message) where TTarget is, in fact, an interface (for example IDisposable). Of course the recipient must register to receive the type of message TMessage.

Sending messages with a token

Messages can now be sent through the Messenger with a token.

  • To send a message with token, use the method overload Send<TMessage>(TMessage message, object token).
  • To receive a message with token, use the methods Register<TMessage>(object recipient, object token, Action<TMessage> action) or Register<TMessage>(object recipient, object token, bool receiveDerivedMessagesToo, Action<TMessage> action)

The token can be a simple value (int, string, etc…) or an instance of a class. The message is not delivered to recipients who registered with a different token, or with no token at all.

Renaming CommandMessage to NotificationMessage

To avoid confusion with ICommand and RelayCommand, the CommandMessage class has been renamed to NotificationMessage. This message class can be used to deliver a notification (of type string) to a recipient.

ViewModelBase constructor with IMessenger

The ViewModelBase class now accepts an IMessenger parameter. If this constructor is used instead of the default empty constructor, the IMessenger passed as parameter will be used to broadcast a PropertyChangedMessage when the method RaisePropertyChanged<T>(string propertyName, T oldValue, T newValue, bool broadcast) is used.

In the default ViewModelBase constructor is used, the Messenger.Default instance will be used instead.

EventToCommand behavior

The EventToCommand behavior has been added in V3. It can be used to bind any event of any FrameworkElement to any ICommand (for example a RelayCommand located in the ViewModel). More information about the EventToCommand behavior can be found here and here.

Updated the project templates to remove the sample application

The project template has been updated to remove the sample application that was created every time that a new MVVM Light application was created in Visual Studio or Blend. This makes the creation of a new application easier, because you don’t need to remove code before you can start writing code.

Bug corrections

Some bugs that were in Version 2 have been corrected:

  • In some occasions, an exception could be thrown when a recipient was registered for a message at the same time as a message was received.

New names for DLLs

If you upgrade an existing installation, you will need to change the reference to the DLLs in C:\Program Files\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries. The assemblies have been moved, and the versions for Silverlight 4 and for WPF4 have been renamed, to avoid some confusion. It is now easier to make sure that you are using the correct DLL.

WPF3.5SP1, Silverlight 3

When using the DLLs, make sure that you use the correct versions.

WPF4, Silverlight 4

When using the DLLs, make sure that you use the correct versions.

 

MVVM Light V3 released at #MIX10

MVVM_White

During my session “Understanding the MVVM pattern” at MIX10 in Vegas, I showed some components of the MVVM Light toolkit V3, which gave me the occasion to announce the release of version 3. This version has been in alpha stage for a while, and has been tested by many users. it is very stable, and ready for a release. So here we go!

What’s new

What’s new in MVVM Light Toolkit V3 is the topic of the next post.

Cleaning up

I would recommend cleaning up older versions before installing V3. I prepared a page explaining how to do that manually. Unfortunately I didn’t have time to create an automatic cleaner/installer, this is very high on my list but with the book and the conferences going on, it will take a little more time. Cleaning up is recommended because I changed the name of some DLLs to avoid some confusion (between the WPF3.5 and WPF4 version, as well as between the SL3 and SL4 versions). More details in the section titled “Compatibility”.

Installation

Installing MVVM Light toolkit is the manual process of unzipping a few files. The installation page has been updated to reflect the newest information.

Compatibility

MVVM Light toolkit V3 has components for the following environments and frameworks:

  • Visual Studio 2008:
    • Silverlight 3
    • Windows Presentation Foundation 3.5 SP1
  • Expression Blend 3
    • Silverlight 3
    • Windows Presentation Foundation 3.5 SP1
  • Visual Studio 2010 RC
    • Silverlight 3
    • Silverlight 4
    • Windows Presentation Foundation 3.5 SP1
    • Windows Presentation Foundation 4
    • Silverlight for Windows Phone 7 series
  • Expression Blend 4 beta
    • Silverlight 3
    • Silverlight 4
    • Windows Presentation Foundation 3.5 SP1
    • Windows Presentation Foundation 4

Feedback

As usual I welcome your constructive feedback. If you want the issue to be discussed in public, the best way is through the discussion page on the Codeplex site. if you wish to keep the conversation private, please check my Contact page for ways to talk to me.

Video, tutorials

There are a few new videos and tutorials available for the MVVM Light toolkit. The material is listed on the Get Started page, under “tutorials”.

 

My program at #MIX10

MIX10Speaker

Getting ready to fly to Vegas and MIX10 is really an exciting time! It is also a very busy time, because we are working on a few projects that will be shown on stage, I have my presentation to prepare, and of course as always the book… though these days it has been a bit on the back burner to be honest ;)

I arrive in Vegas on Sunday evening around 10PM, so I won’t be able to make it to the traditional IdentityMine dinner this year. I am sure it will be fun nonetheless!

My session: Understanding the MVVM pattern

http://live.visitmix.com/MIX10/Sessions/EX14

My session is scheduled on the first day, which is awesome, so I am crossing my fingers and hoping that the MIX team doesn’t change it at the last minute… The session will take place on

Monday, the 15th of March, 2PM, Room Lagoon F

Important: remember that the USA are moving to Summer time on Sunday, so don’t forget to adjust your watches!!

Ask the Experts

On Monday evening, I will attend the Ask the Experts event, which is taking place between 5Pm and 6:30PM in the main meal hall. This will be a great occasion to grab a beer and talk about code.

The Commons

MIX has a great place called the Commons, a great location to chill between sessions, and meet tons of interesting people. I love the Commons and plan to spend a lot of time there to meet as many people as I can.

Parties

I was invited to a few parties, and will do my best to avoid conflicts :) I plan to be at the following events:

  • Silverlight Mixers on Monday evening
  • Insiders MIX party on Tuesday
  • Silverlight partner happy hour on Tuesday too
This is a lot of fun, but at the same time we all know that the best value of a conference is to meet people face to face. This is just the right occasion. 

And on Thursday…

On Thursday I will be attending a Silverlight event at the Luxor. It will be a very busy day, perfect way to end the conference. I fly back home on Friday morning, but due to a long stop in Washington DC (where I intend to go downtown and take pictures… except if the weather is bad, in which case I will probably go to the museum of flight), I will reach home only on Sunday.

Getting hold of me

The best way to reach me during MIX is to send me a message on Twitter. I will regularly tweet my location at the conference, so make sure to come and meet me. I am eager to make new friends, to talk about the fantastic jobs we did in WPF and Silverlight over the past year and hear your war stories!

http://www.twitter.com/lbugnion

 

Schedule for my session at MIX10

Microsoft has published the schedule for the MIX10 sessions. I have a sweet spot, and I dearly hope that it stays this way (Last year I had a great spot, but it was changed last minute and then I had a much better one, “competing” against Vertigo and their Playboy app… yeah try to explain to a bunch of geeks that MVVM is better than Playboy… good luck with that ;) Anyway, this year my sweet spot is on the very first day of the conference (there are workshops on Sunday, but this qualifies as pre-conference), Monday after the keynote which should get everyone pumped and excited.

Schedule and location

I would be really happy to meet y’all at

See you in Vegas (or in video…)

Everything I saw so far hints that this should be a very, very exciting edition of MIX, maybe the most electrifying ever. The great news is that everything will be available even if you cannot make it: The keynotes are typically streamed live, and if you remember last year’s experience at PDC, it is a really good alternative. Built with Silverlight, the feed uses smooth streaming (adjusting the quality according to your bandwidth automatically), possibility to pause and rewind if you miss something, and a great picture quality. As for the sessions, the message at MIX is that the videos will be available online approximately 24 hours after the session is being held. This is a great feat!

So, see you in Vegas (or in video)!

Cheers,

Laurent

Silverlight MVP of the year

MVP_Horizontal_FullColor_cc[1] Here is a quick news from the MVP summit in Redmond. Things here are amazing, with a lot of good news (that will be made public at MIX, so in the mean time I cannot say anything more about it, except that it is awesome). The summit is, amongst other things, an amazing way to connect with other MVPs and with the product group. This is an amazing community to be a part of, full of really smart people.

In that sense, it was a pretty big surprise for me when I got an email announcing me that I had been selected by my peers and by the product group as Silverlight MVP of the year. I am equally happy to say that I am not the only one, and Dave Campbell (of Silverlight Cream fame) was also selected. That makes me especially happy because I had voted for Dave :)

I remember reading the Silverlight MVPs achievements back then, and thinking just WOW, what an amazing group of people to be a part of. It sounds cheesy, but I will say it anyway, any Silverlight MVP should be an MVP of the year :)

Thanks all who voted for me, and here is to an amazing Silverlight year!!

Laurent

Setting up icons for a Silverlight OOB application

In Silverlight 3 and 4, it is possible to create a Silverlight application and to have the user install it on the desktop (aka Out Of the Browser OOB). This is a great way to offer a “light desktop” experience, where the application can be started from a shortcut on the desktop or the Start menu, but running on Silverlight so that you don’t need the full .NET framework, and can run it on PC and Mac as you like. You can even use the application when the PC is offline, which is not possible with an in-browser application. I am very excited about this feature, because I was one of the first to talk about how great such a feature would be to add a piece to the .NET continuum of client applications.

This post will show you how to create a new Silverlight application and enable it to run out of the browser. I decided to write it because of a small issue I had when trying to setup icons for an OOB application I was working on. The icons did not show up, and it was not quite clear why not: No error messages or warnings, it simply didn’t work. Finally, talking to my boss Nate Dunlap made me realize that for some reason the build action for the icons was set to Resource. Changing it to Content instead solved the issue.

To brand your application and make it easily recognizable, you should set icons for it. The icons are used in various locations for the OOB application: On the desktop in the shortcut; in the Start menu; in the taskbar. Getting the icons to show is actually quite easy, if you are careful about some details. Follow the steps:

  • Create a Silverlight application in Visual Studio 2010.
  • Add 4 icons for your application to the project, for example in a folder named “Resources”. You need to add all 4 icons, in PNG format, with sizes 16x16px, 32x32px, 64x64px and 128x128px.
  • Select each icon that you just added, and press F4. This opens the properties panel for the files. Make sure that the Build Action is set as Content, or else the icons will not show!
  • Open the project properties by right clicking on the project in Visual Studio Solution Explorer, and selecting Properties.
  • Select the tab Silverlight.
  • Check the checkbox marked “Enable running application out of the browser”.
  • Click the button marked “Out-of-browser settings”.

 

  • Select each icon corresponding to the desired size.

Fli6E5

 

  • Open the file MainPage.xaml and enter the code shown below. This adds a Button and a TextBlock to the scene.
<StackPanel x:Name="LayoutRoot"
            Background="White">
    <TextBlock x:Name="IntroTextBlock"
               FontSize="24"
               FontWeight="Bold"
               HorizontalAlignment="Center"
               Margin="10" />
    
    <Button Content="Install"
            x:Name="InstallButton"
            Margin="10"
            Width="100"
            Height="50"
            Click="InstallButton_Click" />
</StackPanel>

 

  • Open MainPage.xaml.cs and type the code below.
    • In the constructor, we check if the application is running inside or outside of the browser. Depending on that, we hide the Button by setting its Visibility to Collapsed, and change the text of the TextBlock.
    • If the Button is visible and gets clicked, the corresponding event handler is called. Installing the application requires just one line of code.
public MainPage()
{
    InitializeComponent();

    if (Application.Current.IsRunningOutOfBrowser)
    {
        InstallButton.Visibility
            = System.Windows.Visibility.Collapsed;
        IntroTextBlock.Text = "Check my icons!";
    }
    else
    {
        IntroTextBlock.Text = "Install me first!";
    }
}

private void InstallButton_Click(
    object sender, RoutedEventArgs e)
{
    Application.Current.Install();
}

 

  • Run the application once. You need to install the OOB application before you can debug it in Visual Studio. After starting the app, you should see the following scene:

 

  • Click on the Install button. This displays a confirmation dialog. Note the presence of the 128x128 icon that we defined in the Properties before.

 

  • After pressing OK, the application starts in OOB mode. Notice the small 16x16 icon in the window’s title bar. Also, you should see an icon in the application’s button in the task bar on Windows.

 

  • Close the application and return to the Project Properties page in Visual Studio.
  • Select the Debug tab and set the Start Action to “Installed out-of-the-browser application”. Make sure that you select the correct one.

From now on, when you start the app from Visual Studio (with F5 or Ctrl-F5), the OOB application will start immediately and you don’t need to uninstall and reinstall it.

Conclusion

Creating Out of the Browser applications is really easy in Visual Studio 2010 thanks to the corresponding dialogs. It is also easy to define icons for your application, which helps creating a stronger identity for your software. However, when you do so, make sure that the icons’ build action is set to Content!!

 

Quick tip: Commenting out properties in XAML

Often when you write XAML, you wish you could ignore a property temporarily. In code, it is easy to do: Just comment out the line where the property is set, and you are good to compile.

LayoutRoot.Background = new SolidColorBrush(Colors.Red);
//LayoutRoot.DummyProperty = "Ignored";
/* LayoutRoot.Another = "Ignored too"; */

In XAML it is not so easy, because XML (of which XAML is a dialect) does not have line comments, but only block comments. You can comment out a whole XAML element, but not just one property.

<!--<ThisBlockIsIgnored Hello="World"
                    Again="Blah">
    <Label Content="No parse" />
</ThisBlockIsIgnored>-->
<TextBlock Text="This is parsed"
   Tag="This too"
   <!--DummyAttribute="No parse"-->
   Margin="10"/>
This last blocks creates an error.

Commenting single properties in XAML requires just a little more initial work, but then it is very easy:

  • In the root tag, add a new xmlns statement to import the Open XML markup compatibility elements:
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  • Then, add another xmlns statement mapping a prefix of your choice (I like to use “ignore”) to an URI of your choice (for example “http://www.galasoft.ch/ignore”). Note that this URI does not need to point to anything on the web. This is just a unique resource identifier, something like a unique ID.
xmlns:ignore="http://www.galasoft.ch/ignore"
  • Finally, use the mc:Ignorable property to set the new prefix as ignorable.
mc:Ignorable="ignore"
  • Note: If you already had one ignorable prefix defined (for example the “d” prefix that Expression Blend and the Visual Studio designer use), no problems. Just add the new prefix to the Ignorable list with a space to separate the prefixes.
mc:Ignorable="d ignore"

The XAML parser honors the Ignorable property and will simply ignore any value prefixed by one of the prefixes defined in the list. Do not however use the Blend “d” ignorable prefix, because this has a special meaning for Blend and Visual Studio designer. The way described here defines a brand new prefix without any additional meaning. The “ignore” prefix can be used for properties or for whole blocks (including their content):

Single property:

<TextBlock Text="This is parsed"
   Tag="This too"
   ignore:DummyAttribute="No parse"
   Margin="10"/>

Whole block:

<ignore:ThisBlockIsIgnored Hello="World"
                    Again="Blah">
    <Label Content="No parse" />
</ignore:ThisBlockIsIgnored>  

The MVVM landscape at MIX10

Update: Shawn Wildermuth has changed his session and will be talking about Silverlight Security instead.

The MIX conference this year had an open call for sessions, and 12 sessions were voted by the public out of 169. Surprisingly (or maybe not that surprisingly in fact), 3 sessions out of the 12 have the MVVM pattern in their title. This shows a lot of interest for this pattern which is helping the developer to create decoupled, testable, blendable applications in Silverlight and in WPF.

Since my session is one of the three, I decided to contact the other two speakers (we happen to run in the same circles ;)) and try to coordinate the content. I think that by talking to each other, we can organize our content so that we avoid overlap and offer a wider landscape to the audience.

The two other authors responded positively to my request, and this is roughly how it will look like. Of course some overlap is unavoidable, to set the context right and avoid misunderstandings. After all, MVVM is a pattern, and as such there are multiple possible implementations or even interpretations of the pattern. But I think that this way, you will get a wider, deeper overview of what MVVM has to offer for you today.

Rob Eisenberg’s “Build Your Own MVVM Framework”

Rob is coordinator on the Caliburn project (a very powerful MVVM framework), but this is not a Caliburn talk. Instead, Rob will take some of the features of this framework and demonstrate how to build them from scratch. This should be a must see for the people who want to understand what is involved in a MVVM application, and how to avoid taking a dependency on an external framework. Rob will also talk about additional topics not directly related to MVVM.

Laurent Bugnion’s “Understanding the Model-View-ViewModel Pattern”

In this talk, I will set primary focus on the Blendability, i.e. how to structure your application so that it works great in Expression Blend. For instance, how can you display “design time data” in Expression Blend, so that the designers have something to design against. I will also show some components included in my MVVM Light Toolkit and explain how they can help you solve some issues in your applications. My talk will apply to Windows Presentation Foundation as well as Silverlight.

To be noted

It is nice to note that Rob and I are not employed by Microsoft, but “just” enthusiast users of the technologies we will talk about. There is a great community around Silverlight and WPF, and it is interesting to note that most of the MVVM frameworks (at the exception of PRISM which is not directly an MVVM framework) originate from outside of Microsoft. Let’s spread the word: MVVM is the pattern of choice when you work in WPF or Silverlight. Come visit our sessions, your life as a developer will be changed!

 

Avoiding issues when typing text in Bindings

The Binding class has a few properties that can be set to a text, including spaces. The properties StringFormat, TargetNullValue and FallbackValue are such properties. These properties exist in WPF and newly also in Silverlight 4.

For example, you can type:

Since these strings are typed within the Binding markup extension in XAML, they do not take quote signs, which leads the XAML editor to be a little confused, as the color coding shows: The text after the “This” turns to red in the figure above.

Color alone is not really an issue, but another factor makes these strings very difficult to enter by default: The editor is configured to enter a comma after each Property/Value pair in the Binding expression. If you open the XAML editor and start typing such a binding expression, you will end up with:

Of course this will crash and burn. However you can correct this: In Visual Studio 2010, select the menu Options / Text Editor / XAML / Miscellaneous and uncheck the option “Commas to separate MarkupExtension parameters”.

From now on, commas will not be added automatically, and you will feel free!

 

Talking in Las Vegas: MIX2010 and MVVM

Update: The session is officially on. See the MIX10 website.

MIX10: Speaker

This morning, very early (or very late depending how you see it), I learned that one of the sessions I submitted to the MIX 2010 open call for speakers had been picked by the public. Out of 169 sessions, only 12 were picked, so you imagine my feelings right now. Honestly, I am sure that this will be a good session, but it could have gone either way, and I had prepared myself mentally for the alternative possibility too.

Understanding the Model-View-ViewModel pattern

The Model-View-ViewModel pattern (also called MVVM) is a hot topic in today’s Silverlight and WPF world. This pattern facilitates modern development techniques such as separation of concerns (decoupling), unit testing and test driven development, work with modern tools such as Visual Studio 2010, Expression Blend and more.

In this session, Laurent (a user and promoter of MVVM since 2006) will introduce this pattern to you with many demos. We will talk about the basic components of a modern Silverlight or WPF application, and of additional helpers that will make your life as a developer much easier.

MVVM at MIX

Interestingly, 3 of the 12 open call sessions picked by the audience have “MVVM” in the title. Rob Eisenberg’s “Build Your Own MVVM Framework” and Shawn Wildermuth’s “RIA Services and MVVM: It Can Happen!”, in addition to mine, should cover the topic in depth. After thinking about it, I decided I will contact Rob and Shawn to talk to them about their session, and try to avoid overlap.

On my end, I will probably shift the focus a little more on what MVVM brings you from a designer (well, integrator)’s point of view, and how you can leverage this pattern to create beautiful applications. I will also, of course, talk about the MVVM Light Toolkit, the open source toolkit I have been developing since last year, and which encounters a great success.

Send me your suggestions

I would love to hear if you have topics you would like to hear about during the session. I have a pretty good idea of what I will talk about, but let me know what is really important for you. What aspects of MVVM do you want me to focus on? What components of MVVM Light? Let me know, and I will adapt the content to include these topics!

I am very much looking forward to this session, and will see you in March at MIX!

 

Quick tip: Finding Silverlight 4 documentation fast

The Silverlight 4 documentation is available online from Microsoft. However, it is not the fastest way to find documentation. Instead, you should know that the Silverlight 4 documentation is available online, it is just a little bit hidden.

“Also available for…”

When you navigate to an MSDN page, you will find a box letting you know that the page you are looking for is also available for Silverlight 3, .NET 3.0, .NET 3.5 or .NET 4. For example, here is what the page for System.Windows.Controls.Border shows:

No sign of Silverlight 4 yet. However, it is easy to get to the same page: In the URL of this page, replace the version number (VS.95) with (VS.96).

http://msdn.microsoft.com/en-us/library/system.windows.controls.border(VS.96).aspx

The version numbers are as follows:

  • (VS.85): .NET 3.0
  • (VS.90): .NET 3.5 SP1 (Note that you can also omit the version number altogether for this.
  • (VS.95): Silverlight 3
  • (VS.96): Silverlight 4
  • (VS.100): .NET 4

Of course some classes are not available for some versions, so you might get a Page Not Found.

Feeling lucky? Search from Bing or Google

In Google and in Bing, it is very fast to search for classes, methods or properties: Simply type the following query:

Border class

The first hit returned by the search engine is the MSDN Border class documentation. From there, you can use the navigation shown above. Another cool tip to go even faster: Type the same query followed by the version number. For example

Border class vs.96

Again, the first hit is what you are looking for.

Note: On Google, apparently you can even just type Border class 96 to get the result you want. On Bing, however, it returns other results first. Safer to type the vs. prefix first.

Since I set Bing to be my default search engine on Chrome and in IE8, I can type my queries directly in the browser’s location bar, and get the result page immediately.

MIX 2010: Voting for sessions has begun (I got two)

This year Microsoft decided to have an open call for sessions for the MIX 2010 in Las Vegas. This conference, in case you don’t know it yet, is a great 3 days about modern client technologies, such as ASP.NET, Windows Presentation Foundation and of course Silverlight. This year, MIX is taking place from the 15th to the 17th of March 2010 in the Mandalay Bay hotel in Vegas.

Today, the voting began! I didn’t count them, but there seems to be more than 100 sessions lined up, and the competition is fierce: Only 10 sessions will make the cut and be chosen for MIX. I just reviewed the speakers, and it is a pretty amazing line-up.

On my end, I submitted two sessions (see below). I honestly think that these two sessions will help the attendees become better developers in Silverlight and in WPF. The talks are based on years of experience with these two technologies, on real life projects.

A day in the life of a Silverlight/WPF Integrator

Vote here: http://visitmix.com/opencallvote/Entry?entryId=ADAYIN060

Abstract:

This session proposes an insight in the life of an integrator (sometimes called User Experience Developer or “Devigner”). How do we translate a creative designer’s vision into code, transforming it into interactive applications? What tools do we use, what tricks did we learn? This session will show you how to start from scratch and coordinate designers and developers to create a new rich application in Silverlight or Windows Presentation Foundation. We will see how to architect and structure the application according to the best practices in the field, and what workflows are involved. We will also see how to create and integrate XAML assets into the user interface. You will leave with a much better understanding on how the new integrator role is changing the way that client applications are developed.

You want to create beautiful applications? That’s what I do for a living, come and share the experience!

Having worked as an integrator for quite a few years now, in large distributed teams of developers and designers, I have identified many areas where the process is different from a classic application. The integrator role is a fairly recent role and many firms need guidance to understand how to start developing their Silverlight or WPF applications, and how to move from wireframes to design to development to testing.

We will also review the tools and the tips&tricks that make the life of an integrator easier. This is not just about Expression Blend, but about all the small helpers that facilitate the integration process.

Understanding the Model-View-ViewModel pattern

Vote here: http://visitmix.com/opencallvote/Entry?entryId=UNDERS103

Abstract:

The Model-View-ViewModel pattern (also called MVVM) is a hot topic in today’s Silverlight and WPF world. This pattern facilitates modern development techniques such as separation of concerns (decoupling), unit testing and test driven development, work with modern tools such as Visual Studio 2010, Expression Blend and more.

In this session, Laurent (a user and promoter of MVVM since 2006) will introduce this pattern to you with many demos. We will talk about the basic components of a modern Silverlight or WPF application, and of additional helpers that will make your life as a developer much easier.

From the maker of the MVVM Light Toolkit!

This talk is targeted at developers who keep hearing people talk about the Model-View-ViewModel pattern, but don’t quite know what it is, what it does, and how to get the best out of that. Again, few slides and a lot of code, as we will walk through the creation of a MVVM application and study the components that help separating the concerns in the application. We will also talk about external frameworks that help you creating new MVVM applications.

 

Believe it or not, it’s almost 2010

This year has been a pretty amazing year. A few weeks ago, I was writing about my first year at IdentityMine. A little more than one year ago I was closing the Siemens book (after around 13 years of working into Building Automation, but always from a software engineer perspective) and started the IdentityMine chapter of my life :). As I mention in the post in question, this first year was a very interesting and also challenging year. Interesting because I got to work with some of the best creative people and developers in the world. It’s always such a pleasure when I introduce myself to someone by saying I work at IdentityMine and to see a look of recognition on their face. This firm rocks, and I love being part of it. Challenging, because being the only European employee can be tough at times, even though the team has been amazing in making me a part of the family. To mitigate the distance, technical mediums like Twitter and Facebook, MSN and an IP phone have been super helpful. Of course nothing replaces the face-to-face contact, and my regular trips to Seattle (which will continue in 2010, I will be in Seattle again in February) make wonders to reconnect and continue the relationship. Surprisingly actually, the distance has not been as tough as I thought it might be. Of course it might not be OK for everyone to work this way, but it has been OK for me.

In the past year, I worked on multiple projects, in multiple roles

  • During presales, talking the the clients, identifying their needs, coming up with preliminary technical evaluations. Super interesting especially when you deal with the latest technology to do stuff that has never been done before.
  • Helping out for development tasks, working with a stellar team of developers and learning tons of new stuff in the process.
  • (my main role) Working as an integrator on various Silverlight and WPF projects. The integrator is the “missing link” between designers and developers. I take the inputs from designers and information architects (wireframes, comps) and extract the design assets to integrate them in the application. This is a great role, because you are the one who puts the final touch in the user experience, and it requires a very good knowledge of WPF, Silverlight and XAML, so it is yet another area where I have been learning tons of new things.
  • Consulting work, such as training clients’ teams, guiding them during the projects to make the best out of the technology, especially when designers are involved. This is a relatively new process, to have designers so involved into the application’s development, and I am lucky to have started working with designers very early on production projects. It is great to look back at this experience, analyze it, and then pass it back to clients and the community.
  • Talking at conferences, writing on my blog, interacting with the community and carrying proudly the name IdentityMine in front of people. I love to show what we do, and teach what I learned. I find that teaching and talking about technology is the best way to learn even more, and I love this. The highlight was of course talking at MIX09 (I had a session and took part to a half day workshop too), but all the other talks in various places in the US and in Europe were a fantastic time too.

Some of these tasks involved a lot of travelling, and it was a great year for my passport. Of all the trips, the ones I loved most were the long stay in Seattle in July, which was a great occasion to reconnect with many friends, make new ones, and then have my family join me for a vacation between Seattle, Victoria and Vancouver and then my visit to Macau and Hang Zhou in the summer, my first stay in both places, and I loved it. Of course the yearly pilgrimage to Las Vegas earlier in the year and the shorter trips to Belgium, Germany, Italy were all great times.

Private projects

I also had a few private projects going on in 2009, and had very exciting results. I published my MVVM Light Toolkit, a set of libraries and tools to make MVVM application development easier. It has encountered a great success so far, with hundreds of download (on Codeplex and on my website) and many, many interesting requests, discussions, etc. I am really excited about what is happening there, and will continue to work on it in 2010.

Of course my blog has been keeping me busy too, and I loved to wrote a few in-depth articles about Silverlight, WPF, MVVM and other topics. I saw a constant progression of subscribers this year, which is of course a great feeling, but also made me feel very humble and eager to produce quality articles.

The last big project is also one that is taking a lot of time, which is why the two other projects I mentioned here are maybe going to slow down a little in the beginning of 2010: I started working on Silverlight 4 Unleashed, the sequel to my first book Silverlight 2 Unleashed. This is a huge job, and I hesitated a lot before accepting to write it. I am now in the process of writing, and while it is really something I like to do, it is unavoidable that some things are going to suffer a little from this extra activity. So to the users of MVVM Light, and to readers of my blog, I ask you to be patient and don’t worry, normal activity will resume eventually ;)

And 2010?

2010 is going to be a great year too. My first big trip of the year is going to be to Seattle, again an occasion to meet friends from IdentityMine and from the community. Can’t wait for this trip. The next one should be to MIX10 in Vegas, and those who know me know how much I love this conference, and this year should be no exception. I am also scheduled to talk in a couple of conferences in Europe, more about this later on my blog.

It is a fantastic privilege to be involved in such a wonderful community. To all of you who make this possible, thank you thousand times. You did truly change my life. I cannot wait to see what the future has in store for us, and I am sure 2010 will be an amazing time yet again.

Happy New Year and as usual, Happy Coding!

Laurent