简体   繁体   中英

How do I access Silverlight App.current.resources[“x”] from a class library?

I am new to Silverlight. Arriving just in time to hear MS pronounce it dead on it's legs. :)

In our projected, we have a silverlight app hosted in a aspx page. There are configuration settings in the web.config (that is being transformed) contaning an environment variable to drive Webservice URLs in the View-Model classes.

All the view models are making use of a Common class library to establish the WS connection and wrap some often used WS calls. So when we build the WS, we need to know the environment value so we can divine the correct Service binding. Pretty much every part of this solution is in it's own project file.

Please exclude the crudeness of my illustraion. web.config -> default.aspx -|-> app.xaml -> Xview.xaml -|-> XViewModel.cs -|-> ClassLib -|-> WCF Service.

-|-> is a project boundary.

Any help would be great. Even if it's just a vocabulary lesson.

Thanks in advance.

As i don't know the full architecture and how the library is used i don't know if this would work for you but possibly you can inject the instance. eg have a static property in you library which is used internally and set from the outside:

public static IApp CurrentApp { get; set; }

You probably you will want to declare an IApp interface in your class library which defines the needed functionality to not make it dependent on one specific application class. This interface then can be implemented by the application and the App instance can be assigned to the property.

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