This will be something of a 'Work in Progress' blog item, as I plan to jot down differences between WPF and Silverlight as I find them, either in my own work or from other sources. It can be difficult to keep up to speed on what the precise differences are at any given time. The SDKs, Toolkits, roll out of new editions of both platforms, etc all cause the sands to keep on shifting. Anyhow, I hope those that I do identify will be of help to those of you who are familiar with WPF, but maybe not so much with Silverlight.
The topic headings are listed alphabetically.
In WPF, you can create a Button and assign its Content in the following way:
<Button Margin="5" >Silverlight< SPAN>Button>
In Silverlight, you don't have this facility and have to explicitly identify the Content property:
<Button Margin="5" Content="Silverlight">< SPAN>Button>
Button ClickMode As you would expect, when the Click event of the button will fire depends on this particular setting.
This is more a matter of user expectation than different properties. The WPF Button has a ClickMode property. This is available in both WPF and Silverlight. The three available values are:
The reason why I include it as a difference is that I think it is unlikely that you will often use the 'Hover' option in a desktop application, because that isn't a reaction your users will expect. In a Silverlight, browser based environment, of course, it may well be that users will be happy with a button click firing when they hover over a button. (Actually, I'm not sure that 'hover' is totally accurate. It really seems to fire on the immediate mouse enter action and I haven't found a setting that allows a built in delay.)
The default value - both for WPF and Silverlight - is 'Release'.
Chrome and Decorators
Most of the Chromes and Decorators, which can be used to fine tune control templates to a very detailed level, are not available in Silverlight2.
Silverlight 2 does not support the WPF Commands structure. It does however support the ICommand interface.
Controls (Visual Elements)
It's hard to keep up with the permutations and changes, but I think the following breakdown is accurate:
1. Available in WPF (.NET 3.5, Visual Studio SP1), but not in Silverlight 2:
* These items are not necessary in Silverlight, because it is browser based.
- FlowDocument Readers
- NavigationWindow *
- Page *
- PageFunction *
2. Available in Silverlight 2 , but not in WPF with Visual Studio 2008:
- DataGrid *
- DatePicker *
* These are not included in WPF in Visual Studio 2008, but are downloadable as part of the WPF Toolkit and will almost certainly ship with VS 2010. You can see info and download the WPF Toolkit from here.
3. Available in the Silverlight 2 Toolkit and in WPF in Visual Studio 2008.
4. Available in the Silverlight 2 Toolkit, but not in WPF.
- Data Visualization/Chart Tools
5. Available in the WPF SDK, but not in Silverlight 2.
- Silverlight 2 does not support One-Way To Source binding.
- With WPF, the default binding mode is dependent upon the dependency property, but is usually TwoWay. The default binding mode in Silverlight 2 is OneWay.
- Silverlight does not support Explicit DataBinding. It does however support the key approaches of LostFocus and PropertyChanged.
- Silverlight 2 does not support MultiBinding.
- Silverlight 2 does not support Element Binding (e.g. Binding a Slider value directly to a property on another element).
- Silverlight 2 does not support the ObjectDataProvider.
Silverlight 2 does not support Read Only DependencyProperties.
A Silverlight application is deployed to a web server and hosted in a web browser. (The next version of Silverlight should also include the ability to view the application offline). WPF applications may be deployed as a standard installed application or via Click Once. WPF also offers a browser hosted version - the XAML Browser Application (XBAP). In view of the limitations of XBAPs it is likely that most developers would now choose Silverlight over WPF for browser hosted applications.
The WPF DrawingBrush is not supported in Silverlight 2. However, there is little that this brush does that can't be achieved with other approaches. The key loss would be the ability to tile, but there are workarounds for this.
Effects (as opposed to BitmapEffects, which are no longer recommended for use) are only available in WPF. The next version of Silverlight should have the ability to create Pixel Shaders, and therefore Effects.
WPF has full access to local files in the same way as other .NET desktop applications. Silverlight runs in a Low Trust environment, so Users have restricted access to local files. Access to files in Silverlight is only available by means of the OpenFileDialog and even then is effectively only Read Only access. In Silverlight 2, saving data to file can only be achieved by using Isolated Storage.
By default, WPF hands off much of the heavy duty graphics work to the GPU, assuming that the graphics card meets the minimum specification. Silverlight uses software rendering.
In WPF you can create a Hyperlink by using the Hyperlink element. Generally you use these in Page based applications and FlowDocuments. Silverlight uses the HyperlinkButton.
Both elements use the NavigateUri property to assign the address of the link. The Silverlight version seems to be more versatile. Although it is called 'button', it doesn't have the standard rectangular button appearance. In fact, if you drag one from the Toolbox, you will see its markup in the XAML pane, but nothing shows in the Design pane.
The intention is that you use the HyperlinkButton as a canvas (with a small 'c', not a Canvas element). You then add Content to the button and this is what creates the interface that the user sees. The Content can be anything from a simple single element to a more complex interface - such as a StackPanel which contains multiple elements:
<HyperlinkButton NavigateUri="http://www.devcity.net" Width="60"
<Image Source="ShelfUnit_WithCans.png">< SPAN>Image>
<TextBlock> Click Me! < SPAN>TextBlock>
There are significant differences between the implementation of local isolated storage in Silverlight 2 and WPF. Silverlight 2 restricts the availability of disk space. The default setting is 1 MB. This may be increased with explicit user authorization.
WPF contains more precise Keyboard Key definitions in its Key enumeration. For example, it
WPF implements several properties in KeyEventArgs; Silverlight implements two - Key and PlatformKeyCode.
WPF does not implement PlatformKeyCode. This is used in Silverlight to identify non-Windows keys.
Silverlight only supports a small sub-set of markup extensions. They are:
It is not possible to create your own markup extensions in Silverlight.
Silverlight supports a limited set of Mouse events:
This means that Silverlight doesn't support mouse wheel, left/right mouse button differentiation or any of the PreviewXX mouse events that are available in WPF.
Silverlight 2 is limited to asynchronous network calls.
Silverlight 2 can communicate to Network Resources via Sockets.
Silverlight 2 supports only SOAP 1.1 over HTTP, and does not support other web services not compliant with WS-I Basic Profile 1.0.
Path Based Animations
This feature is not available in Silverlight 2. Linear interpolated and KeyFrame animations are available.
No PrintDialog or Printing facility in Silverlight 2.
Silverlight 2 does not support MergedDictionaries.
Silverlight 2 does not include the FindResource method.
Silverlight 2 only supports Bubbling and Direct Routed Events. WPF also supports Tunneling Events.
WPF desktop applications require FullTrust permission in order to run. XBAPs run with partial trust. Silverlight 2 applications run in low trust.
WPF offers the choice of Named Styles and Typed Styles. Named Styles allow you to set the Style on an element by using its Key. Typed Styles do not have a Key and all elements of the TargetType within scope of the Style will be assigned the Style.
Silverlight doesn't recognize Typed Styles and if they are used, the assignment of the Style will fail silently.
Silverlight doesn't allow the use of the 'BasedOn' feature to inherit from Styles.
When setting the TargetType, Silverlight does not use the markup extension. You simply assign the name of the TargetType in double quotes. If you forget, and force of habit makes you add the curly braces and markup extension in Silverlight, you won't get a design time error, but it will fail at run time.
Silverlight doesn't have the full range of 3D creation tools that are available in WPF.
Silverlight 2 doesn't support the TileMode in ImageBrush.
Silverlight will not accept Triggers and uses the Visual State Manager (VSM) to organize animations and transitions for user interaction. VSM's capabilities currently are limited to the equivalent of standard Style Triggers and EventTriggers. There are no features equivalent to DataTriggers or MultiTriggers in Silverlight.
VSM for WPF will be available soon.
WPF supports the creation of ValidationRules. This feature is not available in Silverlight 2.
Silverlight2 doesn't support WPF's Visual Brush. As this is a brush of very limited use, it's not likely to be much of a problem.
Visual State Manager (VSM)
Currently this is a Silverlight only feature. It will be introduced into WPF in the future.
Visual Studio Designer
Visual Studio 2008 has the facility for you to drag and drop, reposition, resize, etc, elements in the Design pane with WPF. For Silverlight it seems to offer editing tools only in the XAML pane. The Design pane is a kind of 'Read Only' version of what is created in the markup.
This class exists in both WPF and Silverlight 2, but because of differences in the underlying base classes of the two platforms they have different implementations. The key difference is that WPF offers the HitTest method, whereas Silverlight2 uses FindElementsInHostCoordinates.
With the exception of GetChild, GetParent and GetChildrenCount, Silverlight2 doesn't support any of the GetXXX methods found in WPF.
This is a Silverlight only control. The name says it all - basically a TextBox that allows you to include light shaded text to help the user. If memory serves, this was in Kevin's famous Bag o'Tricks.
Note: Most of the differences described above are also included in an excellent White paper comparison document published by Wintellect. You can download a copy from here.