Mercurial > silverbladetech
comparison 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 |
comparison
equal
deleted
inserted
replaced
23:399398841fd0 | 24:a8b50a087544 |
---|---|
1 using System.Windows; | |
2 using System.Windows.Media; | |
3 | |
4 namespace FxRates.UI.Helpers | |
5 { | |
6 public static class XamlHelper | |
7 { | |
8 /// <summary> | |
9 /// Finds a parent of a given control/item on the visual tree. | |
10 /// </summary> | |
11 /// <typeparam name="T">Type of Parent</typeparam> | |
12 /// <param name="child">Child whose parent is queried</param> | |
13 /// <returns>Returns the first parent item that matched the type (T), if no match found then it will return null</returns> | |
14 public static T TryFindParent<T>(this DependencyObject child) where T : DependencyObject | |
15 { | |
16 var parentObject = VisualTreeHelper.GetParent(child); | |
17 if (parentObject == null) return null; | |
18 var parent = parentObject as T; | |
19 return parent ?? TryFindParent<T>(parentObject); | |
20 } | |
21 } | |
22 } |