Trying to create a base class for my Views in my Silverlight 4 Business Application so that common methods are available throughout my application. Unfortunately, doing this causes the following error:
Partial declarations of ‘SomeApp.Views.Home’ must not specify different base classes
It appears that Silverlight is creating another partial class for this View. Is there a way to get this to work?
I tried to specify the Subclass as follows in the XAML of the View:
x:Subclass=”SomeApp.Views.PageBase”
This did not work.
Yes “Sivlerlight” is creating another partial class (actual its Visual Studio / MSBuild that is doing it). When you save a .xaml file that has the build action “Compile” a dynamic .g.i.cs file is created. It contains a partial class that matches the
x:Classproperty and derives from the class represented by the top level node in the Xaml.Hence xaml like this:-
Will generate a MyControl.g.i.cs containing something like:-
The code-behind file must match.
Hence if you are creating a new base class to derive from, your top-level element must match the base class.
See also: how to create Multiple user control that pointing single code behind file in silverlight 4