Mercurial > silverbladetech
diff MetroWpf/FxRates.UI/Helpers/XamlHelper.cs @ 24:a8b50a087544
Stocks and FxRates working, new menu introduced. Working nicely so far
author | adminsh@apollo |
---|---|
date | Tue, 20 Mar 2012 20:18:35 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/FxRates.UI/Helpers/XamlHelper.cs Tue Mar 20 20:18:35 2012 +0000 @@ -0,0 +1,22 @@ +using System.Windows; +using System.Windows.Media; + +namespace FxRates.UI.Helpers +{ + public static class XamlHelper + { + /// <summary> + /// Finds a parent of a given control/item on the visual tree. + /// </summary> + /// <typeparam name="T">Type of Parent</typeparam> + /// <param name="child">Child whose parent is queried</param> + /// <returns>Returns the first parent item that matched the type (T), if no match found then it will return null</returns> + public static T TryFindParent<T>(this DependencyObject child) where T : DependencyObject + { + var parentObject = VisualTreeHelper.GetParent(child); + if (parentObject == null) return null; + var parent = parentObject as T; + return parent ?? TryFindParent<T>(parentObject); + } + } +}