从儿童应用程序分享属性,基地项目 [英] Share Properties from Child app to Base project

查看:147
本文介绍了从儿童应用程序分享属性,基地项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在Windows Phone应用开发:我这里有一个要求



我有3个项目,



1)BaseLibrary项目 - 库项目即电话类库项目



2)ChildApp1 - 的Winodws Phone应用程序



3)ChildApp2 - Windows Phone的应用程序



现在在我的BaseLibrary我有所有的.xaml和的.cs files.In我的孩子我的应用程序有一个cs文件



理念在这里的背后是我的两个子项目的用户界面是完全一样的,所以我添加了所有常用的东西,在一个库项目,并引用我的孩子应用程序。



现在,我对我的孩子应用一些修改



在BaseLibrary:



MainPage.xaml中的文件;

 命名空间BaseLibrary 
{
公共部分一流的MainPage:的PhoneApplicationPage
{
公众的MainPage()
{
的InitializeComponent();

的AppSettings的appSettings =新的AppSettings();
串的appName = appSettings.getAppName();
INT appVersion = appSettings.getAppVersion();

App_Name.Text =的appName;
App_Version.Text =+ appVersion;
}
}
}

在AppSettingsDefaultImpl:

 命名空间BaseLibrary 
{
公共类AppSettingsDefaultImpl
{
公共虚拟字符串getAppName()
{
返回XYZ;
}

公共虚拟INT getAppVersion()
{
返回1;
}
}
}

在AppSettings的



 命名空间BaseLibrary 
{
类的AppSettings:AppSettingsDefaultImpl
{
公共虚拟字符串getAppName()
{
返回getAppName();
}

公共虚拟INT getAppVersion()
{
返回getAppVersion();
}
}
}

在我的子项目:

 命名空间ChildApp1 
{$ b $使用BaseLibrary b:
类的AppSettings:AppSettingsDefaultImpl
{
公众覆盖字符串getAppName()
{
返回ABC;
}

}
}

现在我当我跑我的孩子的项目,我感到它导航到MainPage.xaml中的BaseLibrary项目



但在文件名为.xaml我有这样的:

 的AppSettings的appSettings =新的AppSettings(); 
串的appName = appSettings.getAppName();
INT appVersion = appSettings.getAppVersion();

App_Name.Text =的appName;
App_Version.Text =+ appVersion;

其中的AppSettings是BaseLibrary的一个实例,所以它会从它们的方法获取值BaseLibrary的AppSettings的,但我想它接受来自子项目的实例,并展示我所存在的值,该怎么办呢?



输出我是越来越:



1,XYZ



输出想我要的是:



1,ABC



如果该属性不符合儿童定义程序的时候,应该采取的价值从BaseLibrary。



有没有办法,我可以达致这


解决方案
<任何方式pre> 命名空间BaseLibrary
{
[导出(基地的typeof(AppSettingsDefaultImpl))]
类的AppSettings:AppSettingsDefaultImpl
{
公众覆盖字符串getAppName()
{
返回ABC;
}

}
}

命名空间ChildApp1
{
[导出(子的typeof(AppSettingsDefaultImpl)) ]
类的AppSettings:AppSettingsDefaultImpl
{
公众覆盖字符串getAppName()
{
返回ABC;
}

}
}



然后:

  CompositionContainer中的容器; //覆盖MefBootstrapper 

AppSettingsDefaultImpl的appSettings =
container.GetExport< AppSettingsDefaultImpl>(子);


I am Working on Windows Phone app Development: i have a requirement here.

i have 3 project,

1) BaseLibrary project - library project i.e., Phone Class Library project

2) ChildApp1 - Winodws Phone app

3) ChildApp2 - Windows Phone app

Now in my BaseLibrary i have all the .xaml and .cs files.In my child apps i have one .cs file

Idea behind here is that both my child project UI is exactly same, so i have added all the common stuff in a library project and referenced it to my child apps.

Now, i have few changes in my child apps.

In BaseLibrary :

MainPage.xaml file;

namespace BaseLibrary
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            AppSettings appSettings = new AppSettings();
            string appName = appSettings.getAppName();
            int appVersion = appSettings.getAppVersion();

            App_Name.Text = appName;
            App_Version.Text = "" + appVersion;
        }
    }
}

In AppSettingsDefaultImpl :

namespace BaseLibrary
{
    public class AppSettingsDefaultImpl
    {
        public virtual String getAppName()
        {
            return "XYZ";
        }

        public virtual int getAppVersion()
        {
             return 1;
        }
    }
}

In AppSettings

namespace BaseLibrary
{
    class AppSettings : AppSettingsDefaultImpl
    {
        public virtual string getAppName()
        {
            return getAppName();
        }

        public virtual int getAppVersion()
        {
            return getAppVersion();
        }
    }
}

In my child projects:

namespace ChildApp1
{
    using BaseLibrary;
    class AppSettings : AppSettingsDefaultImpl
    {
        public override string getAppName()
        {
            return "ABC";
        }

    }
}

Now i when i run my child project i am navigating it to MainPage.xaml in BaseLibrary project.

But in the .xaml file i have this:

AppSettings appSettings = new AppSettings();
                string appName = appSettings.getAppName();
                int appVersion = appSettings.getAppVersion();

                App_Name.Text = appName;
                App_Version.Text = "" + appVersion;

where AppSettings is an instance of BaseLibrary, so it will get the values from the methods which are in the AppSettings of BaseLibrary, but i want it to take the instance from child project and display the values which i have there, how can do it ?

Output i am getting :

1, XYZ

Output want i want is :

1,ABC

If the property is not defined in the child app it should take the value from BaseLibrary.

Is there any way that i can acheive this

解决方案

namespace BaseLibrary
{
    [Export("base",typeof(AppSettingsDefaultImpl))]
    class AppSettings : AppSettingsDefaultImpl
        {
            public override string getAppName()
            {
                return "ABC";
            }

        }
}

namespace ChildApp1
{
    [Export("child",typeof(AppSettingsDefaultImpl))]
    class AppSettings : AppSettingsDefaultImpl
        {
            public override string getAppName()
            {
                return "ABC";
            }

        }
}

Then:

CompositionContainer container;// override MefBootstrapper

AppSettingsDefaultImpl appSettings = 
    container.GetExport<AppSettingsDefaultImpl>("child");

这篇关于从儿童应用程序分享属性,基地项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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