Hi Tony, I presume Silverlight has a FindResource()? In WPF that walks up the visual tree looking for the resource, so it should find the item on the page.
Paul On Fri, Jan 22, 2010 at 10:15 PM, Tony Wright <[email protected]> wrote: > Hmmm. That works if I have the resource specified as a > UserControl.Resource within the control, but not if the resource is on the > owning page – it comes back null. > > > > The user control requires access to various ViewModel classes, as there are > combo boxes to populate, so I am reluctant to bind the > UserControl.DataContext to the PriceViewModel, as it is only one of a number > of similar ViewModels needed. But I will have a rethink about this one. > > > > The other thought was whether there was some way to centralise access to > ViewModel classes from within the application. That is, has anyone managed > to put their ViewModel classes in as Application.Resources? > > > > T. > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Miguel Madero > *Sent:* Friday, 22 January 2010 11:10 PM > *To:* ozSilverlight > *Subject:* Re: Accessing page resources from user controls > > > > var viewModel = (PriceViewModel)Resources["YourKey"]; > > Since your UC is inside the page it will get the resources from there. > > > > Are you setting the ViewModel as the DataContext. If so, you can also get > it from there. > > -- > Miguel A. Madero Reyes > www.miguelmadero.com (blog) > [email protected] > > _______________________________________________ > ozsilverlight mailing list > [email protected] > http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight > > -- Paul Stovell
_______________________________________________ ozsilverlight mailing list [email protected] http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight
