Monday, October 4, 2010

Using WPF Themes with WPF 4 gives Error : "Ambiguous type reference"

Using WPF Themes from with WPF 4 and using the WPF Toolkit Feb 2010 which is latest at the moment gives the following Error:

Ambiguous type reference. A type named 'VisualStateManager' occurs in at least two namespaces, 'System.Windows' and 'System.Windows'

WPF Toolkit is required for themes since they took the effort to style the controls in WPF toolkit as well :)

Simply direct the VSM tags to refer to the .NET4 VSM namespace. Open the theme file you want to use and do the following:

  • Add a new xmlns attribute to the root Resource Dictionary Tag: 

xmlns:sw ="clr-namespace:System.Windows;assembly=PresentationFramework"

  • Search and replace all references to elements in vsm namespace with sw: prefix. 
  • Additionally if you want to completely remove dependency on WPF Toolkit you could simply delete the following tags:
    • xmlns:basic="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    • xmlns:primitives="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit" 
    • And remove any controls that are linked to it ... and redirect the ones available in WPF 4 to the sw namespace