Archive for February, 2009

Silverlight Unit Test Framework released

Those who develop Silverlight applications go through some sort of various testings phasing for your applications, and those developers including you may be interested in a few testing frameworks for Silverlight.

The Microsoft Silverlight Unit Test Framework has been developed by Jeff Wilcox of the Silverlight Toolkit project held over on CodePlex, this test framework is utilised by the Silverlight Toolkit team on their own projects, and allows for the unit tests to be conducted inside the browser and has the ability to test the rich controls as well as the entire Silverlight platform.

Check it out: Silverlight Unit Test Framework.

Twilight 1.5: Multiple Views with MVVM

You may have noticed the new look for the Twilight Twitter Badge on my blog a few weeks ago. I wanted to add a few new looks for the badge and got one of them done but then decided I need to spend some more time on it before releasing it because I didn’t like the way the code was turning out. There were a couple of things I didn’t like: The code was too tightly coupled to the views/skins. This made it hard to add new views/skins without duplicating code. The views/skins weren’t blendable at all. To start my rework I began with this post by the Expression Blend/Design team on simulating sample data in Blend . The post is a very simple yet workable solution for displaying design time data in Blend so that you can work on the layout of your application. The only change I made was how I detected design mode . After playing around with that sample I decided that to implement this in Twilight I would need to switch to a Model-View-ViewModel approach so I started doing some research into using this approach with Silverlight. In my research I came across this post by Ryan Keeter on using MVVM in Silverlight. It was a nice simple explanation that made sense to me so I set out to combine the expression team example and this MVVM example. What I ended up with is pretty close to MVVM. I say pretty close because I don’t think it fully fits since the ViewModels hook into some of the Views Storyboard events and also control the Views VisualState transitions. Maybe that fits into MVVM, but it probably breaks some of the rules. However, for this tiny application it makes things a lot easier. I still have multiple Views per ViewModel and the Views have zero code which is what I really wanted. There are two ViewModels that I’m using: ListViewModel and RotatingViewModel. Then on top of these two ViewModels are four Views: Default, Large, Small, and Tiny. ListViewModel Views

Flash vs Silverlight: Custom Loading Splash Screen

If you want to make a fully personalized Silverlight or Flash application, then you shouldn’t miss out this post. Splash Screen is a very user friendly way to notice how long you have to wait for the application to load. You may also add some graphics, advertisements or animations to entertain the users before the they get bored by waiting. Flash and Silverlight have completely different mechanisms in adding the splash screen. Before we start, let’s take a look on the comparisons and demo first.

Read the original post:
Flash vs Silverlight: Custom Loading Splash Screen

Detecting Design Mode in Silverlight

One of the things I’ve been trying to getting a better understanding of is how to make the Silverlight projects I work on more blendable : In general, WPF and Silverlight controls should be “blendable”. ItemsControls need to display representative data within the design surface. The problem, at least for me, is that every example out there to detect design mode uses: var designMode = !HtmlPage.IsEnabled; Since the Html Bridge is disable inside of Blend, this does work for the most part, but what about when your xap is hosted on another server? In this case the Html Bridge is disabled by default so if someone doesn’t configure it correctly they will get your design time data. Mode HtmlPage.IsEnabled Blend false Visual Studio false Local Xap true Remote Xap false* Streaming Silverlight true** * This can be changed to true, but it is disabled by default . ** Enabled by default So I was trying to come up with another method to detect design mode in Silverlight and here is the best I have come up with so far: public bool IsDesignTime() { try { var host = Application.Current.Host.Source; return false ; } catch { return true ; } } What happens is that Application.Current.Host.Source works great when the plugin is hosted in a web page and will return the path to the xap file, but in design mode trying to access that property throws an exception. So if you hit the exception then you’re in design mode, otherwise you’re in a web page. Not super elegant but it feels better to me than checking if the Html Bridge is enabled since that isn’t a true check. Update: As Tom mentions in the comments, you can also use DesignerProperties.GetIsInDesignMode. But if your goal is to make your project more blendable then Visual Studio support might not be important. Mode DesignerProperties.GetIsInDesignMode Blend true Visual Studio false Local Xap false Remote Xap false Streaming Silverlight false So with this check worst case you get no data in the Visual Studio designer, but the Visual Studio designer isn’t that great anyway. Blend is the real goal. So instead instead of the above code you can use this code instead: public bool IsDesignTime() { return DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual); } Thanks for the tip Tom! This work is licensed under a Creative Commons Attribution By license.

See more here: 
Detecting Design Mode in Silverlight

Flash vs Silverlight: Controlling UI Object

This is a new request from my friend Pierre. He wants to implement a POC to demonstrate how to control objects on the stage. That’s a very good sample for your reference if you want to implement some layout application. If you want to add a resize functionality to the object, you may refer to my previous post Image Manipulation - Scale.

Read more from the original source: 
Flash vs Silverlight: Controlling UI Object

Develop Silverlight on Eclipse : Eclipse4SL

Eclipse4SL has been out for a couple of months since the release of Silverlight 2. However, I didn’t do any testing on this tool until yesterday. I have a lot of findings and let’s see it one by one.

Go here to read the rest: 
Develop Silverlight on Eclipse : Eclipse4SL

XAML Presentation and Guidelines

With Silverlight 3 just around the corner, developers and designers are now starting to work in harmony with both layout and code in Blend and VS2008.
Every developer who starts off into coding has their own opinion on how their code should be structured and formatted.
This comes from Martin Fowler’s classic book Refactoring:
There is another user of your source code. Someone will try to read your code in a few month’s’ time to make some changes. We easily forget that extra user of the code, yet that user is actually the most important. Who cares if the computer takes a few more cycles to compile something? It does matter if it takes a programmer a week to make a change that would have taken only an hour if they had understood your code, so clearly the need to present code, especially large amounts of XAML (and yes it can get quite big!) is becoming more a requirement.
When it comes to writing in XAML for Silverlight or WPF, being a fairly new technology, there aren’t too many opinions about talking best practices in comparison to other launguages/markup.
In fact, the definitive guide for XAML guidelines is Jaime Rodriguez’s (site) best practice web cast series and the resulting whitepaper (pdf).

XAML practices series, part1 , XAML practices series, part2 , XAML practices series, part3

Jaime’s whitepaper is a must read for anyone in the Silverlight WPF/E /WPF space.

XAML Formatting

First and foremost, I think formatting is the number one concern.

  • Any attributes should be on a separate line,
  • x:Name should come first, and you should if possible always have an x:Name for every element and related attributes (such as HorizontalAlignment and VerticalAlignment) should be grouped, eg Layout should be group together, text and text styles grouped etc.

Above is a basic XAML Layout to take a name and an email address, as you can see the XAML is quite minimal, but is a little hard to read with all the attributes, taking a closer look at the same code below Figure-A and Figure-B, show the difference between having all the attributes on the same line versus on different lines. In my opinion, Figure-B is much easier to digest than Figure-A.
Figure-A


Figure-B

By having the x:Name first, you can quickly identify what the element is. Once you find the object you are looking for, you can then quickly identify related objects since they are grouped together (such as RadiusX and RadiusY, Width and Height, and HorizontalAlignment and VerticalAlignment).

The biggest complaint about Figure-B is “wasted space”. The code inflates from 8 lines to 30; however, to Martin Fowler’s point, it’s not about you or the computer, it’s about other people being able to read and quickly assimilate to your code.

x:Name is your friend.

Name everything for later.
Try to specify an x:Name attribute for every element in XAML. If nothing else, this will make you think if you really need the object. For example, at times it’s tempting to embed a panel within a panel to achieve a specific layout. After refactoring I find that if I tweaked a margin or used a different kind of panel, there would have been no need for the extra panel. Forcing an x:Name on an object really makes you think of the purpose of that element.
Describe Elements for later reference
Instead of pre or post-fixing element names, give them a descriptive name. Instead of:

  • btnSubmit use SubmitButton,
  • grdMainContent use MainPanelContent,
  • layoutNavPanel use NavigationPanel.

Programmers like using the pre-fix because you can quickly see all of the same type when using intellisense, and you can easily identify the type of an element. Admittedly, I’m from the designer side of things and when i see code with prefixed terminology I have to follow back that cryptic understanding of what its actually doing, and with more and more designers working in Blend as opposed to other tools, they will have to have a better understanding over the prefix’s, so as a developer keep the prefixes descriptive enough that a developer OR a designer can understand (think stkPanel=StackPanel or me=MediaElement).

Lastly, give all panels the same post-fix because you never know if you will have to change the type of a panel.

I assure you, it’s an enormous pain, and large risk, to change the x:Name in a project. For example imagine having to change “BufferGrid” to “BufferCanvas” to “BufferStackPanel”. Not only do you have to change the XAML, you have to ensure all instances in the code are changed too. Better to go with the generic “BufferPanel” and be done with it.

If possible its best if you try to group prefix your canvases so its easier to read later on when you introduce new panel’s or canvases inside Blend.
Steve

Debug Silverlight Easily with SilverlightSpy

Early in the days of Actionscript and Flash coding i found a great nifty tool called SWFDecompiler which reverse engineered swf files in Flash, now it looks like http://firstfloorsoftware.com have release a similar product which allows the viewing of assets within a XAP file, not only can you view any isolated storage data, styles, or user interface code to make up the xap file, but it presents it in a user friendly tree view.

I think this is a great tool that shows alot of potential and great for debugging at runtime your packaged .xap files.

Check it out:

http://firstfloorsoftware.com/silverlightspy/introduction/

Steve

Moonlight 1.0 Released

Novell has just recently anounced the release of version 1.0 of Moonlight (Silverlight on the Linux desktop).

Scott Guthrie has more information about the release for Linux users here.

Microsoft have worked closely with Miguel de Icaza and his team on this project and have delivered a great result.

Novell’s press release is found here

Great to see Silverlight being cross platform!.

Steve

Stargate Global Consulting New Sharepoint Site!

After a few months of Design and Development my company Stargate Global Consulting has released its first live MOSS site based on a number of key technologies, promoting the Microsoft stack in all its glory.

VISIT SITE

With custom web parts, jQuery animation framework (Amazing to use), Virtual Earth integration on Contact page and a great helping of customised dataview webparts binded to Jquery animation frameworks.

MS Live Search integrated into SharePoint!, great use of technolgies all over this site and really does shine as a showcase for future SharePoint sites coming from SGC, with Silverlight playing a keyrole in MOSS and SharePoint Content websites in the future out of SGC.

Checkout the Showcase footer at the bottom of the website (MS Product Buttons) for that WOW factor about the practices SGC provides!

All in all a great pleasure to work alongside the best guys in the SharePoint business on this project!

Cheers

Steve