5

I have a singleton which once hit will load user profile information, I want to make it an application level resource in my SL3 application so that elements across the application can bind to it.

My code version of the instantiaion is a simple

UserProfile x = UserProfile.GetInstance();

I want to be able to do this in xaml in the app.xaml file and in WPF we have the ObjectDataProvider so I can express something like

<ObjectDataProvider MethodName="GetInstance" 
ObjectType="{x:Type local:UserProfile}" x:Key="CurrentUserProfile"/>

I am struggling to find the right implementation for this in SL3.

2 Answers 2

3

As you point out Silverlight doesn't have ObjectDataProvider. If you need a feature it provides such as lazy instantiation you'll need to build a class of your own to handle it. If you don't actually need these features then simply add an instance of the UserProfile to App.Resources on start up:-

 private void Application_Startup(object sender, StartupEventArgs e)
 {
    Resources.Add("CurrentUserProfile", UserProfile.GetInstance());
    RootVisual = new MainPage();
 }
1
  • I was really hoping to accomplish this in pure xaml but if I dont get a xaml based solution from someone soon then I will give you the check mark...thanks. Jan 30, 2010 at 14:27
0

Silverlight has no ObjectDataProvider.

That said,you can use the DataContext of your Silverlight object.....

Application.DataContext = UserProfile.GetInstance();
1
  • 1
    What happens if you then need to assign DataContext on UserControls etc to some real application data as opposed to the peripheral User info? Jan 30, 2010 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.