Porting from WPF to Silverlight: The Missing Pieces, Part 2





5.00/5 (1 vote)
I bring you the sequel for the post found here. These are just more Silverlight 3 missing features I’ve needed while porting a WPF 3.5 application to Silverlight.
I bring you the sequel for the post found here.
These are just more Silverlight 3 missing features I’ve needed while porting a WPF 3.5 application to Silverlight.
So, without further ado:
Style Setter Doesn’t Support Bindings
Description: in Silverlight 3, a style setter can’t set a value to a binding.
Solution by: David Anson
In a nutshell:
Instead of writing:
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
Use the code in the post and write:
<Setter Property="common:SetterValueBindingHelper.PropertyBinding"> <Setter.Value> <common:SetterValueBindingHelper> <common:SetterValueBindingHelper Property="IsSelected" Binding="{Binding IsSelected}" /> </common:SetterValueBindingHelper> </Setter.Value> </Setter>
The code seems completely different but it is just cosmetics, it works as advertised.
Binding Only Works On FrameworkElement Derived Classes
Description: In Silverlight 3, binding only works on classes that derive from FrameworkElement, where in WPF it works on every DependencyObject.
Solution by: Morten Nielsen
http://www.sharpgis.net/post/2009/05/04/Using-surrogate-binders-in-Silverlight.aspx
In a nutshell:
Instead of writing:
<Image> <Image.RenderTransform > <RotateTransform Angle="{Binding Path=Heading}" /> </Image.RenderTransform> </Image>
Use the code in the post and write:
<Image local:SurrogateBinder.Angle="{Binding Path=Heading}"> <Image.RenderTransform > <RotateTransform /> </Image.RenderTransform> </Image>
Template.FindName Doesn’t Exist
Description: Silverlight 3 doesn’t support the FindName function.
Solution by: Bea Stollnitz
http://bea.stollnitz.com/blog/?p=366
In a nutshell:
Instead of writing:
_panel = Template.FindName("PART_PANEL", this) as StackPanel;
Use the code in the post and write:
_panel = TreeHelper.FindDescendent(this, "PART_PANEL") as StackPanel;
Note: Bea has some more excellent tips for porting WPF to SL in this post.
No UniformGrid
Description: Silverlight 3 doesn’t have the UniformGrid control.
Solution by: Jeff Wilcox
http://www.jeff.wilcox.name/2009/01/uniform-grid/
In a nutshell:
Instead of writing:
<UniformGrid Columns="2">
Use the code in the post and write:
<local:UniformGrid Columns="2">
That’s it for now, Arik Poznanski.