简体   繁体   English

如何从类库访问Silverlight App.current.resources [“ x”]?

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

I am new to Silverlight. 我是Silverlight的新手。 Arriving just in time to hear MS pronounce it dead on it's legs. 刚到时听到MS宣告它死在腿上。 :) :)

In our projected, we have a silverlight app hosted in a aspx page. 在我们的项目中,我们在aspx页面中托管了silverlight应用程序。 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. web.config中有一些配置设置(正在转换),其中包含一个环境变量来驱动View-Model类中的Web服务URL。

All the view models are making use of a Common class library to establish the WS connection and wrap some often used WS calls. 所有视图模型都使用Common类库来建立WS连接并包装一些经常使用的WS调用。 So when we build the WS, we need to know the environment value so we can divine the correct Service binding. 因此,当我们构建WS时,我们需要知道环境值,以便我们能够确定正确的Service绑定。 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. web.config-> default.aspx-|-> app.xaml-> Xview.xaml-|-> XViewModel.cs-|-> ClassLib-|-> WCF服务。

-|-> 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. 您可能需要在类库中声明一个IApp接口,该接口定义了所需的功能,以使其不依赖于一个特定的应用程序类。 This interface then can be implemented by the application and the App instance can be assigned to the property. 然后可以由应用程序实现此接口,并且可以将App实例分配给属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows 8问题(为什么要使用App.Current.Resources?为什么要使用GridView项?) - Windows 8 questions (Why App.Current.Resources? Why Use GridView Items?) 如何从Web请求访问.net类库中的资源 - How to access resources in a .net class library from web request 使用WebForms应用程序的类库中的资源 - Use resources in Class Library from WebForms app 如何从Silverlight应用程序内重定向包含Silverlight应用程序的asp.net页面? - How do I redirect the asp.net page that contains a silverlight app from within the silverlight app? Silverlight:如何根据当前设置类动态更新属性? - Silverlight: How do I update properties dynamically in accordance with a current settings class? 如何从App类访问MainPage类的非静态成员? - How do I access MainPage class non-static members from the App class? 如何访问控制台应用程序中的资源? - How do I access resources in a console application? 从通用共享应用访问类库 - Access Class Library from Universal Shared App 如何使用摘要从当前类中获取属性? - How do I use snippets to get properties from the current class? 如何在我的视图模型中从域服务访问数据? Silverlight 5应用 - How do I access the data from my domain service in my view model ? Silverlight 5 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM