本文介绍了项目和使用的数据来自于WPF项目之一绑定之间共享应用程序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有多个项目在其应用程序。让我们只考虑两个现在 ProjectCore ProjectUI

I am working on an Application which has multiple projects in it. Lets just consider two for now ProjectCore and ProjectUI.

我需要把这些项目之间共享应用程序设置。我所做的就是,创造了设置在解决方案层面文件,并添加这些设置在这些项目的链接(添加现有项 - > 添加为链接)。

I need to share Application settings between these projects. What i did was, created Settings file at Solution level and add those settings as link in these projects (Add Existing Item -> Add as Link).

ProjectUI 有一些UIControls是绑定到 Settings.Default 的不同设置。而 ProjectCore 设定值 Settings.Default

ProjectUI has some UIControls that are bind to Settings.Default's different Settings. And ProjectCore sets value to Settings.Default as well.

现在,如果我使用每个项目的设置情况从Settings.Designer,他们将两个不同的实例。所以结合将无法正常工作,如果我设置为从 ProjectCore 一定的价值。

Now if i use each project's Settings instance from Settings.Designer, they will be two different instances. So binding will not work if i set some value from ProjectCore.

ProjectUI 依赖于 ProjectCore ,所以我不能只是添加设置在ProjectUI写在<$包装C $ C> ProjectUI ,并用它来设置从 ProjectCore 。这将创建循环依赖。

ProjectUI depends on ProjectCore, so i can not just add Settings in ProjectUI and write a wrapper in ProjectUI and use that to set value from ProjectCore. This will create circular dependency.

现在我如何共享和设置文件,并保持绑定工作 ProjectUI

Now how can i share and Settings file and keep the binding working for ProjectUI?

推荐答案

希望它可以帮助你,我只是创建一个示例中,我花了两个项目,如你所说,那么我想补充设置为核心项目,并改变其访问修饰符公众并给予其引用的UI,现在我可以访问这些在我的UI项目设置。

Hope it may help you, I just create a sample in which i took two projects as you said, then i add setting to core project and change its access modifier to public and give its reference to UI, now i can access those setting in my UI project.

有关。例如

test.Settings1.Default.SettingTest = "test";

在这里测试的命名空间,设定1是类和默认的设定1类的静态实例。SettingTest是string类型的我的设置。虽然SettingTest是只读的,我改变其desginer.cs定义

here test is namespace, Setting1 is class and Default is static instance of Setting1 class.SettingTest is my setting of type string. Though SettingTest is read-only i change its definition in desginer.cs to

public string SettingTest {
            get {
                return ((string)(this["SettingTest"]));
            }
            set {
                this["SettingTest"] = value;
            }
        }

这篇关于项目和使用的数据来自于WPF项目之一绑定之间共享应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 23:31