0

How can I access an object thats defined in a resource in the app.xaml from a Viewmodel class?

user2025830
  • 872
  • 2
  • 17
  • 37
  • 1
    Why would you want to access XAML resource from ViewModel? It's not supposed to. – Rohit Vats Apr 24 '14 at 16:41
  • I want to have access to the Bing Map object to center the Map because Map center can't be changed by a binding. see this post from me: http://stackoverflow.com/questions/23203968/win-8-app-bing-maps-binding-location – user2025830 Apr 24 '14 at 16:44

1 Answers1

0

You can access resource like this:

var resource = App.Current.Resources["resourceKey"];

But I would suggest not to do that from ViewModel class because that's not MVVM suggests. You should not access any UI component from ViewModel.

Rohit Vats
  • 79,502
  • 12
  • 161
  • 185