类库中的 App.xaml [英] App.xaml in class library

查看:36
本文介绍了类库中的 App.xaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

现在在我的应用程序中,我想编写从我的类库的 App.xaml.cs 类(即 MiEngineApp.xaml.cs)派生的 App.xaml.cs 类.我创建项目时,默认创建了 App.xaml.cs.默认情况下,它是扩展 Application 类,我只是将其更改为 MiEngineApp(Application -> MiEngineApp).这样做之后,我编译了我的应用程序,它在 App.g.i.cs 文件中给出了一个错误.错误消息是'MiApp.App' 的部分声明不得指定不同的基类".如何解决这个错误!

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!.

推荐答案

您还必须更改 App.xaml 文件.所以这将是你的 MiEngine.xaml

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>

和 MiEngine.xaml.cs:

and MiEngine.xaml.cs:

namespace MiEngine
{
    public partial class MiEngineApp : Application
    {

        public MiEngineApp()
        {

这将是从(扩展)MiEngine.xaml 继承的 App.xaml:

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>

注意 z 命名空间的使用,以便我可以引用基类.
以及它的代码隐藏:

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()
        {

这篇关于类库中的 App.xaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆