none
what happened to SetResourceReference ?

    Question

  • In WPF proper you can dynamically reference a resource without having to look it up using SetResourceReference.   What is the equivalent for windows store apps?

    Also, in WPF proper you can use "FindResource" to lookup not only the local ResourceDictionary, but all inherited ones to the root.  How do I do that in windows store apps?

    Notice the questions are related...

    I'm trying not to have to walk the element hierarchy to find the resource.  I can do this, but I'd prefer not to have to:

            internal static T FindResource<T>(this FrameworkElement e, string name)
            {
                object value = null;
                DependencyObject d = e;
                while (d != null)
                {
                    FrameworkElement f = d as FrameworkElement;
                    if (f != null)
                    {
                        if (f.Resources.TryGetValue(name, out value))
                        {
                            return (T)value;
                        }
                    }
                    d = VisualTreeHelper.GetParent(d);
                }
    
                if (App.Current.Resources.TryGetValue(name, out value))
                {
                    return (T)value;
                }
    
                return default(T);
            }
    Is this the recommended implementation of FindResource<T> ?

    Wednesday, December 12, 2012 11:31 PM

Answers