Advertisement

WPF Toolkit and Silverlight compatibility

At PDC the WPF Tookit was made available which provides several new controls to WPF to help bring even more compatibility to the WPF and Silverlight story.  The new controls were the DatePicker, Calendar, DataGrid and the VisualStateManager concept to WPF.  Ribbon controls were also provided to the WPF Toolkit, but are not covered here.

With the introduction of this toolkit, developers now have a way to get some even more common XAML code-base between projects.

Let’s take a look at a very simple example of both UI and code sharing with WPF and Silverlight.  Here’s the simple scenario.  I’m going to use a common “Customer” class that I want to use in both a WPF and Silverlight implementation.  Since there is no binary compatibility for Silverlight and WPF, I’m going to maintain source-level compatibility.  In order to do this, I’m going to create a Silverlight Class Library project and implement my Customer class in that…here’s my simple customer class:

   1: namespace SilverlightClassLibrary1
   2: {
   3:     public class Customer
   4:     {
   5:         public string FirstName { get; set; }
   6:         public string LastName { get; set; }
   7:         public int CustomerId { get; set; }
   8:         public string CustomerLevel { get; set; }
   9:         public DateTime Birthdate { get; set; }
  10:  
  11:         public static ObservableCollection<Customer> GetCustomerData()
  12:         {
  13:             ObservableCollection<Customer> ppl = new ObservableCollection<Customer>();
  14:  
  15:             ppl.Add(new Customer() { FirstName = "Tim", LastName = "Heuer", CustomerId = 1, CustomerLevel = "Platinum", Birthdate = Convert.ToDateTime("9/18/1965") });
  16:             ppl.Add(new Customer() { FirstName = "Ray", LastName = "Ozzie", CustomerId = 1, CustomerLevel = "Gold", Birthdate = Convert.ToDateTime("1/12/1960") });
  17:             ppl.Add(new Customer() { FirstName = "Bill", LastName = "Gates", CustomerId = 1, CustomerLevel = "Silver", Birthdate = Convert.ToDateTime("12/1/1976") });
  18:             ppl.Add(new Customer() { FirstName = "Bart", LastName = "Simpson", CustomerId = 1, CustomerLevel = "Tin", Birthdate = Convert.ToDateTime("7/4/1985") });
  19:  
  20:             return ppl;
  21:         }
  22:     }
  23: }

Now in my Silverlight project and my WPF application I add a linked file to that class library for customer.  While not binary compat, each time I compile I’m using a common source compat for both projects.  Here’s what my project structure looks like and you can see the linked source code:

Now in my WPF project I want to add some XAML, so I’ll add this to my Window1.xaml:

   1: <Window x:Class="WpfSampler.Window1"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
   5:     Title="Window1" Height="600" Width="600">
   6:     <Grid>
   7:         <StackPanel Orientation="Vertical" Margin="15">
   8:             <TextBlock Text="Your Birthdate" />
   9:             <controls:DatePicker x:Name="MyBirthdate" Text="9/18/1965" />
  10:             <controls:DataGrid Height="400" x:Name="CustomerList"/>
  11:         </StackPanel>
  12:     </Grid>
  13: </Window>

Here’s the backing source code logic for the simple windows app:

   1: namespace WpfSampler
   2: {
   3:     /// <summary>
   4:     /// Interaction logic for Window1.xaml
   5:     /// </summary>
   6:     public partial class Window1 : Window
   7:     {
   8:         public Window1()
   9:         {
  10:             InitializeComponent();
  11:             Loaded += new RoutedEventHandler(Window1_Loaded);
  12:         }
  13:  
  14:         void Window1_Loaded(object sender, RoutedEventArgs e)
  15:         {
  16:             CustomerList.ItemsSource = SilverlightClassLibrary1.Customer.GetCustomerData();
  17:         }
  18:     }
  19: }

Now in my Silverlight project I’m going to paste the same XAML:

   1: <UserControl x:Class="SilverlightWpfReuse.Page"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   4:     xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
   5:     xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
   6:     Width="600" Height="600">
   7:     <Grid x:Name="LayoutRoot" Background="White">
   8:         <StackPanel Orientation="Vertical" Margin="15">
   9:             <TextBlock Text="Your Birthdate" />
  10:             <controls:DatePicker x:Name="MyBirthdate" Text="9/18/1965" />
  11:             <data:DataGrid Height="400" x:Name="CustomerList"/>
  12:         </StackPanel>
  13:     </Grid>
  14: </UserControl>

and here’s the Silverlight source code logic as well:

   1: namespace SilverlightWpfReuse
   2: {
   3:     public partial class Page : UserControl
   4:     {
   5:         public Page()
   6:         {
   7:             InitializeComponent();
   8:             Loaded += new RoutedEventHandler(Page_Loaded);
   9:         }
  10:  
  11:         void Page_Loaded(object sender, RoutedEventArgs e)
  12:         {
  13:             CustomerList.ItemsSource = SilverlightClassLibrary1.Customer.GetCustomerData();
  14:         }
  15:     }
  16: }

So if you have a keen eye you’ll see it’s not full cut/paste as you note the xmlns declarations in the root control.  Since the implementations are in two different assemblies (System.Windows.Controls.dll for Silverlight and Microsoft.Windows.Controls.dll for WPF Toolkit) we have to make sure they are referenced accordingly.  We can still use the same prefix though of “controls” so that we have greater re-use across our XAML.  For DataGrid, we need to do an additional step since for Silverlight it is on its own assembly.

If we run these applications here is what we get:

WPF Application:

Silverlight application:

Sure we had to do some maneuvering (xmlns stuff) but if you have some great XAML/code you can still get some good re-use out of those implementations with little effort and share code!

So what about VisualStateManager?  How do you use that in WPF if you already have something in Silverlight?  Let’s simplify it to the most common/basic control – Button.  Using Blend we’ve styled a simple Button control and Blend has generated the appropriate VSM resources for us (note that I am not a designer and just used Blend to quickly make 2 changes that probably look horrible :-):

   1: <Style x:Key="StyledButton" TargetType="Button">
   2:             <Setter Property="Background" Value="#FF1F3B53"/>
   3:             <Setter Property="Foreground" Value="#FF000000"/>
   4:             <Setter Property="Padding" Value="3"/>
   5:             <Setter Property="BorderThickness" Value="1"/>
   6:             <Setter Property="BorderBrush">
   7:                 <Setter.Value>
   8:                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
   9:                         <GradientStop Color="#FFA3AEB9" Offset="0"/>
  10:                         <GradientStop Color="#FF8399A9" Offset="0.375"/>
  11:                         <GradientStop Color="#FF718597" Offset="0.375"/>
  12:                         <GradientStop Color="#FF617584" Offset="1"/>
  13:                     </LinearGradientBrush>
  14:                 </Setter.Value>
  15:             </Setter>
  16:             <Setter Property="Template">
  17:                 <Setter.Value>
  18:                     <ControlTemplate TargetType="Button">
  19:                         <Grid>
  20:                             <vsm:VisualStateManager.VisualStateGroups>
  21:                                 <vsm:VisualStateGroup x:Name="CommonStates">
  22:                                     <vsm:VisualState x:Name="Normal"/>
  23:                                     <vsm:VisualState x:Name="MouseOver">
  24:                                         <Storyboard>
  25:                                             <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity">
  26:                                                 <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
  27:                                             </DoubleAnimationUsingKeyFrames>
  28:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
  29:                                                 <SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF"/>
  30:                                             </ColorAnimationUsingKeyFrames>
  31:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
  32:                                                 <SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF"/>
  33:                                             </ColorAnimationUsingKeyFrames>
  34:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
  35:                                                 <SplineColorKeyFrame KeyTime="0" Value="#7FE61212"/>
  36:                                             </ColorAnimationUsingKeyFrames>
  37:                                             <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
  38:                                                 <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFEE4B4B"/>
  39:                                             </ColorAnimationUsingKeyFrames>
  40:                                         </Storyboard>
  41:                                     </vsm:VisualState>
  42:                                     <vsm:VisualState x:Name="Pressed">
  43:                                         <Storyboard>
  44:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
  45:                                                 <SplineColorKeyFrame KeyTime="0" Value="#FFF40B0B"/>
  46:                                             </ColorAnimationUsingKeyFrames>
  47:                                             <DoubleAnimationUsingKeyFrames Storyboard.TargetName="BackgroundAnimation" Storyboard.TargetProperty="Opacity">
  48:                                                 <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
  49:                                             </DoubleAnimationUsingKeyFrames>
  50:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
  51:                                                 <SplineColorKeyFrame KeyTime="0" Value="#D8FFFFFF"/>
  52:                                             </ColorAnimationUsingKeyFrames>
  53:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
  54:                                                 <SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF"/>
  55:                                             </ColorAnimationUsingKeyFrames>
  56:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
  57:                                                 <SplineColorKeyFrame KeyTime="0" Value="#8CFFFFFF"/>
  58:                                             </ColorAnimationUsingKeyFrames>
  59:                                             <ColorAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)">
  60:                                                 <SplineColorKeyFrame KeyTime="0" Value="#3FFFFFFF"/>
  61:                                             </ColorAnimationUsingKeyFrames>
  62:                                         </Storyboard>
  63:                                     </vsm:VisualState>
  64:                                     <vsm:VisualState x:Name="Disabled">
  65:                                         <Storyboard>
  66:                                             <DoubleAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity">
  67:                                                 <SplineDoubleKeyFrame KeyTime="0" Value=".55"/>
  68:                                             </DoubleAnimationUsingKeyFrames>
  69:                                         </Storyboard>
  70:                                     </vsm:VisualState>
  71:                                 </vsm:VisualStateGroup>
  72:                                 <vsm:VisualStateGroup x:Name="FocusStates">
  73:                                     <vsm:VisualState x:Name="Focused">
  74:                                         <Storyboard>
  75:                                             <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity">
  76:                                                 <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
  77:                                             </DoubleAnimationUsingKeyFrames>
  78:                                         </Storyboard>
  79:                                     </vsm:VisualState>
  80:                                     <vsm:VisualState x:Name="Unfocused"/>
  81:                                 </vsm:VisualStateGroup>
  82:                             </vsm:VisualStateManager.VisualStateGroups>
  83:                             <Border x:Name="Background" Background="White" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
  84:                                 <Grid Margin="1" Background="{TemplateBinding Background}">
  85:                                     <Border x:Name="BackgroundAnimation" Opacity="0" Background="#FF448DCA"/>
  86:                                     <Rectangle x:Name="BackgroundGradient">
  87:                                         <Rectangle.Fill>
  88:                                             <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
  89:                                                 <GradientStop Color="#FFFFFFFF" Offset="0"/>
  90:                                                 <GradientStop Color="#F9FFFFFF" Offset="0.375"/>
  91:                                                 <GradientStop Color="#E5FFFFFF" Offset="0.625"/>
  92:                                                 <GradientStop Color="#C6FFFFFF" Offset="1"/>
  93:                                             </LinearGradientBrush>
  94:                                         </Rectangle.Fill>
  95:                                     </Rectangle>
  96:                                 </Grid>
  97:                             </Border>
  98:                             <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" x:Name="contentPresenter" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
  99:                             <Rectangle x:Name="DisabledVisualElement" IsHitTestVisible="false" Opacity="0" Fill="#FFFFFFFF" RadiusX="3" RadiusY="3"/>
 100:                             <Rectangle Margin="1" x:Name="FocusVisualElement" IsHitTestVisible="false" Opacity="0" Stroke="#FF6DBDD1" StrokeThickness="1" RadiusX="2" RadiusY="2"/>
 101:                         </Grid>
 102:                     </ControlTemplate>
 103:                 </Setter.Value>
 104:             </Setter>
 105:         </Style>

There is nothing more we have to do in Silverlight since VSM is a part of the core.  We just annotate our Button with the style:

   1: <Button Content="Styled Button" Style="{StaticResource StyledButton}" />

Now in WPF we can use those same resources by adding them to our Grid.Resources node in our Window1.xaml file.  The thing is that we don’t need the vsm: prefix.  A simple find/replace removes them and we have our style button.  The resulting full XAML for the style looks the exact same (minus any vsm: prefix) and the XAML for the button also looks the same.

I think there has to be a better way to use linked files here as well, so I’ll think about that and report back if I find one.  I know this is a very simple demonstration of only a bit beyond Hello World, but I hope at least it gets you thinking of how you can get source-level compatibility and some XAML re-use out of your Silverlight and WPF applications. 

What are your thoughts?  Have you found better ways?  What are the stumbling blocks you are facing in code sharing?


This work is licensed under a Creative Commons Attribution By license.

  1. 11/10/2008 5:44 PM | # re: WPF Toolkit and Silverlight compatibility
    My WPF app crashes when setting the DatePicker's IsEnabled property to false.
  2. 11/10/2008 8:29 PM | # re: WPF Toolkit and Silverlight compatibility
    Like the idea of sharing short cut file :-)
  3. 11/10/2008 9:33 PM | # re: WPF Toolkit and Silverlight compatibility
    I can't believe WPF didn't have a DataGrid before. The VisualStateManager in Silverlight is really nice and will be a nice add for WPF.
  4. Gravatar
    11/10/2008 10:11 PM | # re: WPF Toolkit and Silverlight compatibility
    I like the linking idea for normal C# code, but I've found it impossible to link Xaml (doesn't compile). Is there a way to share Xaml UserControls between Silverlight and WPF projects?
  5. 11/11/2008 1:19 AM | # re: WPF Toolkit and Silverlight compatibility
    Hi Tim,

    first of all, thank you for great article.

    I was thinking about the Idea of sharing code between projects. Theoretically, if you set some boundaries and rules. And you will develop WPF project according to those rules. Then, I think, is possible to build a configurable tool which will inspect the code and create SL-compatible copy.

    Someone in our company needed a way to share as much code as we can. So that we can offer the customer two types of deployment. I am curious about your opinion.

    Peter
  6. 11/11/2008 2:42 AM | # re: WPF Toolkit and Silverlight compatibility
    Microsoft really needs to come up with a reasonable desktop/browser compat scenario like Adobe Flex has. So-so source compatibility is better than nothing but Silverlight out-of-the-browser will solve many of the annoying WPF/SL compat issues for many basic applications that don't need the power of the full WPF framework.
  7. 11/11/2008 6:31 AM | # re: WPF Toolkit and Silverlight compatibility
    JC: Agreed on XAML linking -- I'm trying to investigate a concept on how to do that myself.

    Peter: Such a tool would be great. An even better idea would be to incorporate that into some type of automated build/continuous integration step so it does it automatically?

    Borek: We're looking at all types of customer feedback. What types of scenarios do you feel this will aid (other than just parity with Adobe AIR)? Are you using AIR now?
  8. 11/11/2008 7:24 AM | # re: WPF Toolkit and Silverlight compatibility
    The latest Silverlight Toolkit has a very interesting AutoCompleteBox that is not currently included in the WPF Toolkit. Do you know of any plans for this?
  9. 11/11/2008 7:39 AM | # re: WPF Toolkit and Silverlight compatibility
    Tim,

    It would be a huge win for Microsoft and for developers who currently support web and desktop versions of the same product (namely me), if there were an automated build step to do this. Surely there is someone at Microsoft who could spend a week throwing together something that, at least, let you go from Silverlight --> WPF in an automated fashion. *I think if this could happen at the UserControl level that would be fine.* (An entire application would be a show stopper -- clearly you can't bring in some silverlight APIs that only make sense in a browser host, nor can you bring in WPF desktop IO APIs, etc.)

    The main reason for doing this is so that an app can be primarily web-based but ported easily to desktop when you need to access local resources, support offline mode, or more importantly, interface with connected devices (think music players, healthcare devices, etc.)

    Completely random question while I hopefully have your attention -- is there any plan to put Silverlight on the Wii?

    Pete
  10. 11/11/2008 7:58 AM | # re: WPF Toolkit and Silverlight compatibility
    Hi I'm not borek but i though of leaving my vision of the problem.

    My most recent project in the company i work was to develop an SL application for document visualization for the health industry. If i got the versions correct i think i worked on the first version of SL with c# support, the 1.1.
    A while ago i was asked to put that working for WPF as well... It took me a few days (i cutted a lot of functionalities, added others). After finishing it, i couldn't stop thinking that most of the conversion work was very repetitive and the creation of a conversion tool shouldn't be a big problem for a company like Microsoft.
    There's of course problems with the HTML related classes that simply don't make sense in WPF and should be ignored by the conversion toll, but without imagining the whole cenario where there's a Flex like tecnology from Microsoft, this should at least provide some help for developers in my conditions.
  11. 11/11/2008 9:28 AM | # re: WPF Toolkit and Silverlight compatibility
    Hi Tim, yes, Flex programming for both Flash Player and Adobe AIR runtimes are part of my day job and having one unified development framework is a fantastic feature that I have appreciated many times. It's great to see that WPF/SL is heading in the same direction (and I was absolutely flabbergasted when ScottGu announced the out-of-browser version of Silverlight during his PDC keynote) although you're in a slightly more complicated position than Adobe was - they believed in a unified framework from day one while Microsoft pushed a strategy of two similar but focused frameworks. That is not intrinsically bad but the differences were just too annoying and it's great to see them blur.

    On a side note, if you would be interested in a feedback on SL/WPF programming model from someone with experience with Adobe Flex, feel free to contact me at borekb@gmail.com. I like .NET from day one and would love to contribute to make WPF/SL shine :)
  12. 11/11/2008 10:16 AM | # re: WPF Toolkit and Silverlight compatibility
    We have already found many cases where WPF and Silverlight isn't XAML and code compatible. For instance in many cases WPF wants us to use x:Key instead of x:Name in Silverlight (storeboards in resources is one example and we can't use FindName anymore then).
    In code they also behave very different when creating animations programmatically, giving very weird (unhelpful) exceptions in WPF.

    What I'm getting at is that its far from the no-brainer to reuse code between WPF and SilverLight that Microsoft says it is. I attended the session on this very topic at the PDC, and I was shocked that none of this was touched on. It only dealt with the simple stuff that obviously works. Not the pitfalls which would have been valuable information, suggestions such as using compiler conditions to truly reuse code etc.
  13. Gravatar
    11/11/2008 11:20 AM | # re: WPF Toolkit and Silverlight compatibility
    perhaps this is a stupid question, b ut cant one simply use the silverlight datagrid in a wpf app? how much work whould it be to enable that?
  14. 11/11/2008 2:41 PM | # re: WPF Toolkit and Silverlight compatibility
    Thats even better idea Tim :-)
    I can imagine some kind of LOB-Talk integration tool.
    You would just define mappings from wpf to silverlight, for example namespaces. Then some rules and converters to deal with not supported features (like remove this Element binding or convert that markup extension to xaml declaration).

    Tools configuration would naturally evolve with the project (and it would be configurable in XAML :-P).

    Every build it would create SL version of software and point out things it cant handle. Those will be taken care of by "integration team".

    Full support for Composite Application Guidance is matter of fact.

    Now we only need to write it.

    Peter

  15. 11/11/2008 2:43 PM | # re: WPF Toolkit and Silverlight compatibility
    JayG: I don't know of plans for the AutoCompleteBox for WPF, but that isn't a part of the core Silverlight controls. It is a part of an Open Source project. In theory you can take that code and work it for WPF!
  16. 11/11/2008 2:45 PM | # re: WPF Toolkit and Silverlight compatibility
    Pete: Regarding the Wii (and the iPhone, etc., etc.). Microsoft is interested in seeing Silverlight wherever there is a browser. Of course resource constraints have a lot to do with making this a reality sooner than later. With regard to things like the Wii and the iPhone...the question should be *when will Nintendo and Apple enable their platforms for plug-ins in their browsers*? Until that question is answered first, any speculation/effort on our part might not be worth it.
  17. 11/11/2008 2:48 PM | # re: WPF Toolkit and Silverlight compatibility
    aL: The DataGrid in Silverlight and WPF share the same functionality...I'm not sure I understand your question?
  18. 11/11/2008 2:49 PM | # re: WPF Toolkit and Silverlight compatibility
    Morten: You are absolutely right that today not all would be cut/paste-able (and sorry if I'm giving that impression here that it is). I'm merely presenting here a technique at some of the possibilities. We have a lot of work to do for full compat!
  19. 11/11/2008 2:51 PM | # re: WPF Toolkit and Silverlight compatibility
    Peter: I think the team for Prism is looking at compat for the Composite App Building.
  20. 11/12/2008 12:46 PM | # re: WPF Toolkit and Silverlight compatibility
    Yes, the AutoCompleteBox in the Silverlight Toolkit will be added to the WPF Toolkit, though I can't comment on a specific date. Ditto for the charting components.
  21. 11/13/2008 3:07 PM | # re: WPF Toolkit and Silverlight compatibility
    Tim,

    Sharing code between WPF and Silverlight has been a major issue for me as I have been building the Silverlight version of our Virtual Tour Viewer. I'm going to write a major blog article on exactly how I've managed to achieve it, as well as providing an open source WPF compatibility library which provides WPF functionality on Silverlight such as routed commands, routed events, FlowDocumentViewer, navigation etc.

    One of the things that I decided to do early on was separate my data access classes, like customer in your example, into a separate project. What I then did was create a Silverlight project in the WPF project in the same folder. One of the problems with this is that they both want to output to the debug folder. Therefore in the Silverlight project I have them outputting to a Silverlight debug folder.

    I have entirely different solutions for both WPF and Silverlight projects which I've found easier from a management perspective.

    For projects other than the data access layer I have created entirely different folders and entirely different projects, this is principally because if I'm using the same folders and I have completely different generic.xamls's between Silverlight and WPF I haven't found a way to make that work. Since Silverlight is a subset I use the WPF folders as my principal folder and add any required files as linked files into the Silverlight project.

    Now comes the interesting part. Dealing with xaml files. I have managed to get linked xaml files working, but I haven't actually found a single xaml file across my project where they are the same between WPF and Silverlight. This is a substantial annoyance and creates a huge amount of additional work.

    So given that situation I virtually always share the code behind .cs file but not the .xaml file.

    Anyway I will post in substantially more detail on my blog, in the next couple of weeks.

    ...Stefan
  22. 11/14/2008 9:53 AM | # re: WPF Toolkit and Silverlight compatibility
    Stefan: I think it would be most beneficial to hear your stories from the front lines on this!
  23. 11/17/2008 4:07 AM | # re: WPF Toolkit and Silverlight compatibility
    Very nice post, Silverlight is the one!
  24. 11/17/2008 4:28 PM | # re: WPF Toolkit and Silverlight compatibility
    Hi, I'm currently working on the Prism team, and as Tim mentioned, we're developing guidance on how to build LOB apps that can sometimes target both frameworks (Silverlight and WPF).
    In our latest drops we released a tool where you link 2 projects and automatically create links in the target project when a file is added/renamed/deleted from the source project. It is just a basic tool, but can save you lots and lots of work (actually we built it for ourselves and decided that the community might benefit from it too).
    You can get this tool (that is a VS Package) separated from the actual Prism code, so you don't have to take everything if you want to just start using the Project Linker.
  25. 11/20/2008 3:15 AM | # re: WPF Toolkit and Silverlight compatibility
    Hi, this all looks very similiar to what I am going through. My pain point is the differences in MediaElement between WPF and Silverlight. For example silverlight can access multiple audio tracks, WPF cannot. One has a Script event, the other requires a workaround. I am happy with one being a subset of the other, but having non-overlapping features is making this tough. Can we at least get an interim update to WPF to create feature parity here?

    Overall I would kill for a framework that permits targeting both environments. This would be a killer feature for Microsoft.
  26. 11/20/2008 3:30 AM | # re: WPF Toolkit and Silverlight compatibility
    By the way, you can go a bit further with this. If you match the namespace and class name of the Window/Page classes in the WPF/Silverlight code you can then link additional files with partial class definitions that are common to both. This is a neat way to add a common implementation of methods and properties to the overall class. Within that file you can use the SILVERLIGHT macro to handle minor differences.
  27. 11/20/2008 10:30 AM | # WPF toolkit failing
    I have used the DatePicker with no problems in SL applications. However, when creating a normal (stand alone) WPF application the program crushes if I try Disable the DatePicker.
    example:
    ...







    Test this and tell me if you get the same error:
    'PART_DisabledVisual' name cannot be found in the name scope of 'System.Windows.Controls.Grid'.

  28. 11/21/2008 10:07 AM | # re: WPF Toolkit and Silverlight compatibility
    Is there any reason that there is still no NumericUpDown control for WPF? I cannot imagine why this control was simply left out - especially since Silverlight now gets this very control. As long as WPF does not provide all the controls Windows.Forms did, porting applications can be really problematic.
  29. 11/21/2008 10:47 AM | # re: WPF Toolkit and Silverlight compatibility
    Stephan: Silverlight doesn't have this control in the core framework or SDK. Rather NumericUpDown is provided by the Toolkit (not a part of core). These are controls that *may* make there way back into core. For now, the full source code for the NumericUpDown is available and could be ported for WPF client.
  30. 11/22/2008 6:34 AM | # re: WPF Toolkit and Silverlight compatibility
    Thanks for the answer Tim. I hope that these controls will make their way back into both the core Silverlight and WPF frameworks.
  31. 12/2/2008 2:43 PM | # re: WPF Toolkit and Silverlight compatibility
    Does this mean we can use the performance tools in vs.net 2008? (man, silverlight is really hard to performance tune out of the box)
  32. 12/2/2008 3:00 PM | # re: WPF Toolkit and Silverlight compatibility
    Todd: what would you like out of perf testing for Silverlight? What are your expectations and what tools would you want to use?
  33. 12/2/2008 7:47 PM | # re: WPF Toolkit and Silverlight compatibility
    Daniel: regarding your error, I can repro as well and saw someone logged it already: www.codeplex.com/.../View.aspx?WorkItemId=8188
  34. 12/16/2008 3:33 PM | # re: WPF Toolkit and Silverlight compatibility
    Just curious, do the Silverlight/WPF developers realise that instead of solving the problem of the code reuse across multiple platforms they created a new, bigger problem? Solving problems is always good, but not creating them is much better.
    Both .NET compact framework and desktop framework are binary compatible, and that means that the same binary modules can run on both platforms. Of course, there are some limitations applicable, but for the most code it runs just fine. And it makes the customer happy!
    The competitor's product JavaFX from Sun is also able to run on any platform where Java runs. And the same compiled binary code runs across all the platforms supported by Java.
    I believe that creating this compatibility issue between Silverlight and WPF was a big mistake, and the company is gonna be sorry for it.
  35. 12/18/2008 5:02 AM | # re: WPF Toolkit and Silverlight compatibility
    Alexander: I agree.Binary compatible would have been big selling point here.
  36. 1/17/2009 5:04 AM | # Amazonpower
    Wow, I never knew that WPF Toolkit and Silverlight compatibility. That's pretty interesting...
  37. 10/22/2009 7:46 AM | # re: WPF Toolkit and Silverlight compatibility
    If only the WPF Toolkit controls had the nice Silverlight theme out of the box.

 
Please add 4 and 2 and type the answer here:
First time here? You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting! (hide this)