Click here to Skip to main content
11,501,968 members (65,522 online)
Click here to Skip to main content

Tagged as

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

, 23 Sep 2010 Ms-PL 6.8K 2
Rate this:
Please Sign up or sign in to 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. So, without further ado: Style Setter Doesn’t Support Bindings Description: in Silverlight 3, a style setter can’t set a value to a

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

http://blogs.msdn.com/b/delay/archive/2009/05/07/one-more-platform-difference-more-or-less-tamed-settervaluebindinghelper-makes-silverlight-setters-better.aspx

http://blogs.msdn.com/b/delay/archive/2009/11/02/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx

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.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Arik Poznanski
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).
Follow on   Twitter   Google+

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 23 Sep 2010
Article Copyright 2010 by Arik Poznanski
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid