Monday, October 4, 2010

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

Using WPF Themes from http://wpfthemes.codeplex.com/ 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 :)

Solution:
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
Enjoy!

4 comments:

  1. solved the exact problem i was having this morning

    ReplyDelete
  2. gracias muchachas, got me burrito to compile!

    ReplyDelete
  3. Have you ever thought about including a little bit more than just your articles?

    I mean, what you say is valuable and all.
    But think about if you added some great images or video clips to give your posts more, "pop"!

    Your content is excellent but with images and videos, this blog
    could definitely be one of the best in its niche. Amazing
    blog!

    my blog - hostpapa Testimonials

    ReplyDelete