public static T FindResource <T>([NotNull] this FrameworkElement element, [NotNull] string name) { while (element != null) { if (element.Resources.TryGetValue(name, out object result)) { return((T)result); } element = element.FindParent <FrameworkElement>(true); } return((T)Application.Current.Resources[name]); }