public static T TryFindAncestorOrSelf <T>([NotNull] this DependencyObject self, [NotNull] Func <T, bool> match) { Contract.Requires(self != null); Contract.Requires(match != null); return(self.AncestorsAndSelf().OfType <T>().FirstOrDefault(match)); }
public static IEnumerable <DependencyObject> Ancestors([NotNull] this DependencyObject self) { Contract.Requires(self != null); Contract.Ensures(Contract.Result <IEnumerable <DependencyObject> >() != null); return(self.AncestorsAndSelf().Skip(1)); }
private static RouterService WalkAncestorsForRouterService(DependencyObject dependencyObject) { var routerService = from ancestor in dependencyObject.AncestorsAndSelf() let service = RoutingComponent.GetRouterService(ancestor) where service != null select service; return(routerService.LastOrDefault()); }
/// <summary> /// Determines whether the routed event args should be handled. /// </summary> /// <param name="args"></param> /// <returns></returns> /// <remarks>This method prevents parent frames from handling routed commands.</remarks> private bool HandleRoutedEvent(CanExecuteRoutedEventArgs args) { DependencyObject originalSource = args.OriginalSource as DependencyObject; if (originalSource == null) { return(false); } return(originalSource.AncestorsAndSelf().OfType <ModernFrame>().FirstOrDefault() == this); }
/// <summary> /// When overridden in a derived class, returns a <see cref="T:System.Windows.DataTemplate" /> based on custom logic. /// </summary> /// <param name="item">The data object for which to select the template.</param> /// <param name="container">The data-bound object.</param> /// <returns> /// Returns a <see cref="T:System.Windows.DataTemplate" /> or null. The default value is null. /// </returns> public override DataTemplate SelectTemplate(object item, [CanBeNull] DependencyObject container) { if ((item == null) || (container == null)) { return(null); } var frameworkElement = container.AncestorsAndSelf().OfType <FrameworkElement>().FirstOrDefault(); if (frameworkElement == null) { return(null); } var key = DataTemplateManager.CreateKey(item.GetType(), Role); return((frameworkElement.TryFindResource(key) as DataTemplate) ?? FallbackValue); }
/// <summary> /// Returns a collection containing this element and all ancestor elements /// which match the given type. /// </summary> public static IEnumerable <DependencyObject> AncestorsAndSelf <T>(this DependencyObject item) { return(item.AncestorsAndSelf().Where(i => i is T).Cast <DependencyObject>()); }
/// <summary> /// Gets the message to show when an export provider could not be located in the visual tree. /// </summary> /// <param name="obj">The object.</param> /// <returns>The message.</returns> public static string GetMissingExportProviderMessage(this DependencyObject obj) { return("Export provider must be registered in the visual tree " + string.Join("/", obj.AncestorsAndSelf().Reverse().Select(o => o?.GetType().Name))); }
/// <summary> /// Returns a collection containing this element and all ancestor elements /// which match the given type. /// </summary> public static IEnumerable <T> AncestorsAndSelf <T>(this DependencyObject item) { return(item.AncestorsAndSelf().OfType <T>()); }
public static T TryFindAncestorOrSelf <T>([NotNull] this DependencyObject self, [NotNull] Func <T, bool> match) { return(self.AncestorsAndSelf().OfType <T>().FirstOrDefault(match)); }
public static T TryFindAncestorOrSelf <T>([NotNull] this DependencyObject self) { return(self.AncestorsAndSelf().OfType <T>().FirstOrDefault()); }
public static IEnumerable <DependencyObject> Ancestors([NotNull] this DependencyObject self) { return(self.AncestorsAndSelf().Skip(1)); }
internal static string GetMissingExportProviderMessage([NotNull] this DependencyObject obj) { Contract.Requires(obj != null); Contract.Ensures(Contract.Result <string>() != null); return("Export provider must be registered in the visual tree " + string.Join("/", obj.AncestorsAndSelf().Reverse().Select(o => o?.GetType().Name))); }