App.xaml在类库中

sai*_*esh 3 windows-phone-7

我已经创建了一个windows phone 7自定义类库,我已经创建了App.xaml和App.xaml.cs文件(我已将它们重命名为MiEngineApp.xaml,MiEngineApp.xaml.cs和我的类库的名称是MiEngine) .我在我的应用程序中引用了类库.

现在在我的应用程序中,我想要从我的类库的App.xaml.cs类(即MiEngineApp.xaml.cs)派生的App.xaml.cs类.创建项目时,默认情况下创建了App.xaml.cs.默认情况下,它扩展了Application类,我只是把它改为MiEngineApp(Application - > MiEngineApp).执行此操作后,我编译了我的应用程序,它在App.gics文件中出错.错误消息是"MiApp.App'的部分声明不得指定不同的基类".如何解决这个错误!

slu*_*ter 6

您还必须更改App.xaml文件.所以这将是你的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>
Run Code Online (Sandbox Code Playgroud)

和MiEngine.xaml.cs:

namespace MiEngine
{
    public partial class MiEngineApp : Application
    {

        public MiEngineApp()
        {
Run Code Online (Sandbox Code Playgroud)

这将是继承自(扩展)MiEngine.xaml的App.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>
Run Code Online (Sandbox Code Playgroud)

请注意z命名空间的使用,以便我可以引用基类.
而代码背后:

namespace SilverlightApplication6
{
    public partial class App : MiEngineApp
    {

        public App()
        {
Run Code Online (Sandbox Code Playgroud)