.NET & Funky Fresh

Syndication

News

  • <script type="text/javascript" src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822/US/bluspiconinc-20/8001/8b68bf4b-6724-40e7-99a5-a6decf6d8648"> </script>
Porting NHProf from WPF to Silverlight – Day 1

This is a true story. It’s a story about porting a non-trivial WPF application, NHProf, to Silverlight 4. The story begins today with my first actual work on the porting process. Microsoft has been preaching how easy it is to move between these platforms. Are they telling the truth? I’ll (try to) let you be the judge. I’ve been a bit lax in my blogging lately, but I’m going to try and give a semi-regular account of my progress on this port along with the challenges I meet along the way. Perhaps I’ll be able to offer some meaningful workarounds that others can use; perhaps not. Maybe, dear reader, you can recommend some solutions to me.

Today I spent about 6 hours on the Silverlight version of NHProf. I basically did a File->New Project and began moving small pieces of the application shell over to Silverlight. The new application is not much to see at this point…most of the UI is missing entirely.

NHProf Silverlight Progress Day 1 

 

 

Below is a summary of the platform inconsistencies I came across in the first six hours of work:

  1. Xmlns – Silverlight 4 allows assemblies to define custom Uri-based Xml namespaces. Unfortunately, Microsoft has done a rather poor job of using this feature themselves. The first issue I came up against today was related to this. It’s not a big problem, but rather an annoyance. The reason is that some controls are in different assmelbies/namespaces in Silverlight than in WPF. Take DockPanel, for example. It’s a core Panel in WPF, but not in Silverlight. Microsoft hasn’t patched up the namespaces for this, so if you port code using DockPanel, you have to go add custom xmlns everythwere. Yuck. This is true of everything in the Silverlight Toolkit. It would be really nice if they took everything in the SDK and everything in the Toolkit and just put them in the default namespace. Unfortunately, this one issue is probably going to prevent a direct reuse of any of our views.
  2. TabControl – If you have seen the NHProf UI, It’s fairly obvious that we rely heavily on the TabControl. Unfortunately, the Silverlight TabControl is completely broken for data binding. Furthermore, it doesn’t have all the necessary template properties either. Basically, it’s completely different from the WPF version and completely unusable if you are using an MVVM architecture. My work around has been to use a horizontal ListBox for the “tabs” and a ContentControl for the “SelectedItem,” then rely on styling to make it look like a tab control. You can see this in the screenshot above (minus the styling of coarse).
  3. ToolTip vs. ToolTipService – In WPF, every control has a ToolTip property; not so in Silverlight. You have to use an attached property called ToolTipService.ToolTip instead. Again, not a big problem, but it forces me to change every view.
  4. Grid.IsSharedSizeScope and ColumnDefinition.SharedSizeGroup – Missing. There’s no way I know of to do a shared size scope layout in Silverlight. We used this quite a bit in the WPF version. Most of our “data grids” are actually list boxes with shared size scope layout. It was just simpler and more light weight. To solve this, I’m actually using the Sivlerlight DataGrid control. You can see it in the screen shot above displaying the Session Statistics. Ultimately, I think this will be an improvement to the UI. It just seams a bit heavy-weight considering that all of our grids are readonly. Suggestions?
  5. ItemsControl.AlternationCount – Missing. This was primarily used in the style to generate alternating row colors. Since most of our ItemsControls/ListBoxes are going to be switched to DataGrid, this probably won’t be a big deal in the end. Still, I’d be interested in knowing what the proper way to do alternating row styles in Silverlight is.
  6. TextTrimming="CharacterEllipsis" – Missing.  We just have to go with WordEllipsis or roll our own ;(
  7. DynamicResource – Missing. I’ve temporarily removed all the styles for the views I have ported. I’m really not sure what the ramifications of the missing DynamicResource will be in the end.
  8. HeaderedContentControl Template uses a StackPanel – The HeaderedItemsControl’s template is built wrong…Period. It uses a StackPanel for layout and that prevents styling the control to expand properly. It should use a DockPanel. As I mentioned above, DockPanel is not in the core, which is probably why the HeaderedItemsControl is broken. Now, if they would just move the DockPanel….
  9. ContextMenu – Missing. Silverlight offers mouse right-click support, but no ContextMenu out of the box. We are going to have to build this one from scratch.
  10. DispatcherTimer(DispatcherPriority.Normal) – There’s no notion of DispatcherPriority in silverlight! So usage of the Dispatcher and DispatcherTimer can be quite different. Unfortunately, I won’t know the full effect of this until we start pushing lots of data through this thing…I don’t think it will be a problem. But, when it comes to SL vs. WPF, I’ve learned not to take anything for granted.
  11. RegexOptions.Compiled – Missing. We’ll just have to do without that.
  12. String.StartsWith - Missing overload for culture. Created an extension method as workaround.
  13. StringBuilder - Missing overload to insert a character. Created an extension method as workaround.
  14. DateTimeFormatInfo - Missing GetAllDateTimePatterns. Created an extension method as workaround. Faked the implementation…

Hmm.  That’s a bit disconcerting for a mere six hours in. What’s interesting to note are the the differences in core APIs. I expected the graphics stack to have some inconsistencies, but I didn’t expect to hit BCL differences so quickly. I also expected to get a lot more of the shell done today. Looking at the screenshot above….I’m a bit embarrassed at the lack of progress. So far, porting WPF to Silverlight is slow going.


Posted 03-25-2010 4:33 PM by Rob Eisenberg

[Advertisement]

Comments

Troels Richter wrote re: Porting NHProf from WPF to Silverlight – Day 1
on 03-25-2010 4:50 PM

Very interesting! looking forward to your next step!

People who think silverlight is a subset for WPF will be dissapointed. silverlight and wpf is developed by different teams and cannot be ported easily.

I see silverlight as Microsofts change to get rit of some of WPF's complexity.

Christopher Bennage wrote re: Porting NHProf from WPF to Silverlight – Day 1
on 03-25-2010 4:58 PM

#7 has been my biggest concern (at least before reading your post). We've relied heavily on dynamic resources for the various looks of the apps.

Brad wrote re: Porting NHProf from WPF to Silverlight – Day 1
on 03-25-2010 5:47 PM

It is so hard to go from WPF -> Silverlight.  Its easy to do Siliverlight -> WPF.  WPF just has way too many features Silverlight just doesnt.  I have tried it for a few small things and gave up and just stuck w/ a ClickOnce app.

Bruno Martinez wrote re: Porting NHProf from WPF to Silverlight – Day 1
on 03-26-2010 12:44 PM

As a Silverlight/WPF control implementor, I feel the same pain.  In my opinion, custom Uri-based Xml namespaces is the best Silverlight 4 feature.  Maybe you could edit the toolbox assemblies to add the uri used by the built in assemblies.

IMO, DockPanel is less useful than it seems.  I use StackPanels or jump straight to Grids. DockPanel behavior when not everything fits and the order the children get clipped is unnatural to the user that doesn't know the order the elements were inserted.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)