简体   繁体   中英

Share application settings between projects and use data binding from one of the project in wpf

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 has some UIControls that are bind to Settings.Default 's different Settings. And ProjectCore sets value to Settings.Default as well.

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

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

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.

for. eg

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

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;
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM