saikamesh
saikamesh

Reputation: 4629

App.xaml in class library

I have created a windows phone 7 custom class library, in that I have created App.xaml and App.xaml.cs files also(I have renamed them as MiEngineApp.xaml, MiEngineApp.xaml.cs and my class library's name is MiEngine). I have referenced the class library in my application.

Now in my application, I want to wrte App.xaml.cs class derived from my class library's App.xaml.cs class(that is MiEngineApp.xaml.cs). When I created the project, App.xaml.cs was created by default. It is by default extending Application class, I just chaged this to MiEngineApp(Application -> MiEngineApp). After doing this I compiled my application, it gives an error in the App.g.i.cs file. The error message is "Partial declarations of 'MiApp.App' must not specify different base classes". How to solve this error!.

Upvotes: 3

Views: 3181

Answers (1)

slugster
slugster

Reputation: 49974

You also have to change the App.xaml file. So this will be your MiEngine.xaml

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="MiEngine.MiEngineApp"
             >
    <Application.Resources>

    </Application.Resources>
</Application>

and MiEngine.xaml.cs:

namespace MiEngine
{
    public partial class MiEngineApp : Application
    {

        public MiEngineApp()
        {

This will be the App.xaml that inherits from (extends) MiEngine.xaml:

<z:MiEngineApp xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="SilverlightApplication6.App"

             xmlns:z="clr-namespace:MiEngine;assembly=MiEngine"
             >
    <z:MiEngineApp.Resources>

    </z:MiEngineApp.Resources>
</z:MiEngineApp>

Note the use of the z namespace so that i can reference the base class.
And the codebehind for that:

namespace SilverlightApplication6
{
    public partial class App : MiEngineApp
    {

        public App()
        {

Upvotes: 6

Related Questions