我有一个单例,一旦点击它就会加载用户配置文件信息,我想让它成为我的SL3应用程序中的应用级资源,这样整个应用程序中的元素就可以绑定到它。
我的实例化代码版本是一个简单的
UserProfile x = UserProfile.GetInstance();我希望能够在app.xaml文件中用xaml来做这件事,在WPF中我们有ObjectDataProvider,所以我可以表达如下内容
<ObjectDataProvider MethodName="GetInstance" 
ObjectType="{x:Type local:UserProfile}" x:Key="CurrentUserProfile"/>我正在努力在SL3中找到正确的实现。
发布于 2010-01-30 16:59:49
正如你所指出的,Silverlight没有ObjectDataProvider。如果您需要它提供的特性,比如惰性实例化,那么您需要构建一个自己的类来处理它。如果你实际上不需要这些功能,那么只需在启动时将UserProfile的一个实例添加到App.Resources:
 private void Application_Startup(object sender, StartupEventArgs e)
 {
    Resources.Add("CurrentUserProfile", UserProfile.GetInstance());
    RootVisual = new MainPage();
 }https://stackoverflow.com/questions/2166852
复制相似问题