andrew4582

UIElementExtentions

Nov 14th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. using System.Windows.Media;
  2.  
  3. namespace System.Windows
  4. {
  5.     public static class UIElementExtentions
  6.     {
  7.         public static T FindVisualParent<T>(this UIElement element) where T : UIElement
  8.         {
  9.             UIElement parent = element;
  10.             while (parent != null)
  11.             {
  12.                 T correctlyTyped = parent as T;
  13.                 if (correctlyTyped != null)
  14.                 {
  15.                     return correctlyTyped;
  16.                 }
  17.                 parent = VisualTreeHelper.GetParent(parent) as UIElement;
  18.             }
  19.             return null;
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment