annotate MetroWpf/FxRates.UI/Helpers/XamlHelper.cs @ 105:1c9fc59af186

Removing old files
author stevenhollidge <stevenhollidge@hotmail.com>
date Sun, 06 May 2012 12:32:35 +0100
parents a8b50a087544
children
rev   line source
24
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
1 using System.Windows;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
2 using System.Windows.Media;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
3
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
4 namespace FxRates.UI.Helpers
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
5 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
6 public static class XamlHelper
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
7 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
8 /// <summary>
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
9 /// Finds a parent of a given control/item on the visual tree.
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
10 /// </summary>
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
11 /// <typeparam name="T">Type of Parent</typeparam>
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
12 /// <param name="child">Child whose parent is queried</param>
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
13 /// <returns>Returns the first parent item that matched the type (T), if no match found then it will return null</returns>
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
14 public static T TryFindParent<T>(this DependencyObject child) where T : DependencyObject
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
15 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
16 var parentObject = VisualTreeHelper.GetParent(child);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
17 if (parentObject == null) return null;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
18 var parent = parentObject as T;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
19 return parent ?? TryFindParent<T>(parentObject);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
20 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
21 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
22 }