PureMVC EmployeeAdmin for Silverlight demo

PureMVC EmployeeAdmin for Silverlight demo

As I promised on the PureMVC forums, I ported the Flex PureMVC EmployeeAdmin demo to Silverlight using PureMVC Standard for C#.

When I'll get some sufficient code review and Cliff has time to, I'm pretty sure that he'll add it to the PureMVC C# port for Silverlight as a demo.

This was my first real Silverlight application. I learned a lot from this work. I now have a better understanding of Silverlight, its pros and cons. As you may know, I'm specialized in Flex/Flash development, so you'll probably be interested in my opinion regarding Silverlight compared to Flex.

I worked with Visual Studio 2010 beta 2 and Silverlight 4 beta tools because both was free. This was a real nightmare. I'm pretty sure that's because both products are beta, but Visual Studio constantly crashes when debugging the application in the browser. I found no way to debug Silverlight in Visual Studio outside of the browser. I suppose that it would help not to crash so often. Note that it seems to work better when using Internet Explorer instead of Chrome or Firefox.

I learned later that Visual Web Developer express 2008 allows to code Silverlight for free with no limitation, but it has no design view and for the moment work only with Silverlight 3. There is a Visual Web Developer 2010 beta which works with Silverlight 4 but it installs near all the Visual Studio 2010 beta environment. Not a good choice in my case as I already had VS 2010 installed.

You'll see later that using Silverlight 4 was a good choice as I had some problems with data-binding in Silverlight 3.

This passed, my first fear was the PureMVC for C# Silverlight library won't work with Silverlight 4. But no problem, it worked immediately.

I noted some tiny things to improve in the PureMVC C# port, as the Body, Type, Name members used in the INotification interface while PureMVC is designed to use respectively GetBody, Gettype, GetName to be easily compatible with other languages as Java that doesn't support getter/setter syntax. Also, the namespace of the classes in the pattern package are shortened from the last package (PureMVC.Patterns.Notification instead of PureMVC.Patterns.Observer.Notification, etc...).

Converting ActionScript 3 code of the EmployeeAdmin PureMVC part to C# was pretty easy. It took me more time to create the XAML view. I simply built it all from scratch. But even this part was less complicated than I originally thought. XAML is finally very similar to MXML.

Problems started with data-binding. First I was new to Silverlight and there were only few examples and advanced open-sourced applications on the Internet. But even this said, I must admit that data-binding in XAML is not so intuitive. Data-binding in Silverlight does not support code bribes in XAML components properties attributes as in Flex, it always need a Class or a XAML resource as target when only a short expression is needed in Flex to execute some complex operations.

The better example of this is the submitButton of the Userform in the Flex EmployeeAdmin demo :

<mx:Button
    id="submitButton"
    click="submit()"
    label="{ ( mode == MODE_ADD ) ? 'Add User' : 'Update User' }"
    enabled="{ enableSubmit( username.text, confirm.text, password.text, department.selectedItem as DeptEnum ) }"
/>
 

In the Silverlight, binding the enabled property to a method is possible but ridiculously complex regarding what I just need. Finally I preferred to change the property by code with a validation method because it was easier. Also note that to solve this specific form validation problem I didn't find any pre-built UI component to display errors in field nor easy to implement validation strategy. There's some but not fitted for this PureMVC demo as it still needs more extra classes and more XAML resources declaration.

I also had some problems to bind XAML to code-behind. It seems that XAML is not thought to bind XAML components properties to code-behind members. We always does this in Flex when we bind some component properties to MXML hosted script members.

Here, the solution I used :

<userControl
    x:Class="MyClass"
    [....]
    Name="myCodeBehind"
>
    <grid x:Name="LayoutRoot">
        <someComponent SomeProperty="{Binding MyMember, ElementName=myCodeBehind}" />
    </grid>
</userControl>
 

It works as intended in Silverlight 4, but it seems not in Silverlight 3, as you will see later.

Finally the application works well and was not so hard to build as I intended first. Excepted problems with Visual Studio 2010 and data-binding, I must admit that it was a good experience.
Once again I was also really happy to use PureMVC to switch from one technology to another. This done, the application logic almost worked immediately. I like this kind of magic a lot.

You can launch the live demo, download or browse the sources.

If you haven't done it yet, you'll need to install Silverlight 4 beta player to run the demo otherwise as it still beta it will not automatically download the right version. Look for the Windows Runtime or Mac Runtime in this page it directly downloads the installer.

If you want to build the project, you'll need to follow the instructions steps to install Visual Studio 2010 and Silverlight 4 on the Siverlight.net website.

As said, the project was made with and for Visual Studio 2010 beta 2 and Silverlight 4 beta. I am currently working on a Silverlight 3 version, but as I'm having trouble with data-binding in Silverlight 3, I'm not sure to release it. If your interested in, sources for the Silverlight 3 version I'm working on can be downloaded and browsed. The problem here seems that binding between the XAML page with the properties of the code-behind does not work. The better example is the binding of the ItemsSource property of the DataGrid to the Users code-behind property which initialize all the UI. I'm pretty sure it can be done.

3 thoughts on “PureMVC EmployeeAdmin for Silverlight demo

  1. Pingback: Twitter Trackbacks for Tekool.net - Développeur Flash - PureMVC EmployeeAdmin for Silverlight demo [tekool.net] on Topsy.com

  2. I have updated the demo to v1.1.2 to add support for the new PureMVC Employee Admin demo design and code rules. I also worked to make the Silverlight application identical to the Flex one.

    Now the Flex and Silverlight demo are near the same and offer a good playground to test differences between both.

  3. Today I updated the demo and the project to make it works with Visual Studio 2010 final version and Silverlight 4 Toolkit final release.

    Note for record that it also works with Web Developer 2010 express version.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

  Am Not Spammer

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>