A day in the life...

public class GeekEarth : Earth { }
posts - 14, comments - 22, trackbacks - 0

Thursday, July 23, 2009

Partial declarations of must not specify different base classes

I wanted to use a common base class for a set of UserControls in my WPF application, but when I changed the class’s ancestor in the code file and compiled I would get the error

“Partial declarations of must not specify different base classes”

This is because when you compile a WPF application Visual Studio generates a partial class in a code-behind file automatically, the base type specified is always “UserControl”.  To solve this problem change your XAML from this

   1:  <UserControl
   2:    x:Class="MyApp.MyControl"
   3:  />

To this

   1:  <local:SomeBaseTypeYouWantToUse
   2:    x:Class="MyApp.MyControl"
   3:    xmlns:local="clr-namespace:NameSpace.To.Your.BaseClass"
   4:  />

posted @ Thursday, July 23, 2009 12:08 PM | Feedback (7) | Filed Under [ Code ]

Powered by: