Reference to System.Windows.dll missing while porting the BasicMVVMQuickStart to WPF

Topics: Prism v4 - WPF 4
Nov 15, 2012 at 6:17 PM

Hi,

I am stuck with a simple Problem. I want to "port" the BasicMVVMQuickStart from Silverlight to WPF. I've Setup a new Project, imported files and references but can't get over a build error that states that the dependency from

System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"

can't be resolved. I know thats a Silverlight assembly. I have a couple of copies of that dll but None with that version number and referencing one of these lead to another bunch of Errors due to double referencing.

Does anybody know where to find that specific Version of System.Windows.dll?

 

Regards,

Peter

 

Developer
Nov 16, 2012 at 6:08 PM

Hi Peter,

As far as we know not all assemblies provide the ability to run on both Silverlight and .NET runtimes. For example this could be the case of the System.Windows.dll used in Silverlight applications. For more information about the binary compatibility support between Silverlight and WPF you can check the following article:

Take into account that porting from one platform to the other might not always be straightforward as some features may not be available for both platforms and because of the differences between the XAML in Silverlight and WPF. In some cases you may have to change the namespace used in your Silverlight application to match the WPF equivalents. An example of this could be the VisualStateManager class which in Silverlight can be located in the System.Windows.dll assembly but its WPF version is defined in the PresentationFramework.dll assembly.

You can find more detailed information about these differences in the following resources:

 

So far, we have been able to port the Basic MVVM QuickStart from Silverlight to WPF following this:

  1. Create a new WPF project named BasicMVVMApp. This is the same as name of the namespace used in the Basic MVVM QuickStart's classes. (You can name you WPF project with a different name, but then you will have to change the namespace of the aforementioned classes manually.)

  2. Add a reference to Microsoft.Practices.Prism

  3. Modify the App.xaml to add the following resources:

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Theme/Theme.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    
  4. Create two new folders in your WPF project, named Images and Theme.

  5. Import the following files of the original Basic MVVM QuickStart:

    • In your WPF project import the files: Questionnaire.cs, QuestionnaireView.xaml, QuestionnaireView.xaml.cs, QuestionnaireViewModel.cs.
    • In your Images folder import the info.png file.
    • In your Theme folder import the Theme.xaml file.
  6. Open your MainWindow.xaml window and replace its XAML code with the contents of the MainPage.xaml view of the original Basic MVVM QuickStart, including the namespaces. You should replace everything except for the x:Class attribute of the MainWindow.xaml window.

  7. Open the Theme.xaml file you imported before, and remove the following namespace:

    • xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
  8. Then, find any references to the aforementioned namespace inside this file and change them to use the default namespace which is set to use the PresentationFramework.dll assembly. For example, you have to change:

    <vsm:VisualStateManager.VisualStateGroups>
    <!-- to: -->
    <VisualStateManager.VisualStateGroups>
    
  9. Finally, find the following styles inside the Theme.xaml file and change their x:Name attribute to x:Key. This is because Silverlight supports an x:Name on a ResourceDictionary item and can use x:Name as a substitute for x:Key. However, WPF does not support this behavior, and you have to use an x:Key instead.

    • QuestionLabelStyle
    • ToolTipImageStyle
    • BorderBrush
    • HeaderedBorderStyle

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Nov 19, 2012 at 8:03 AM

Hi Damian,

 

That was really helpful - thanks a lot (I probably wouldn't have figured out all the differences by myself and would probably have given up on this sample).

 

Kind regards,

Peter