-
Notifications
You must be signed in to change notification settings - Fork 5
/
Helpers.cs
73 lines (68 loc) · 2.45 KB
/
Helpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.ComponentModel;
using System.Windows.Data;
using System.Collections.Generic;
using System.Windows;
using System;
using System.Windows.Media;
namespace FancyGrid
{
public static class Helpers
{
//public static string GetSortMemberPath(DataGridColumn column)
//{
// // find the sortmemberpath
// string sortPropertyName = column.SortMemberPath;
// if (string.IsNullOrEmpty(sortPropertyName))
// {
// DataGridBoundColumn boundColumn = column as DataGridBoundColumn;
// if (boundColumn != null)
// {
// Binding binding = boundColumn.Binding as Binding;
// if (binding != null)
// {
// if (!string.IsNullOrEmpty(binding.XPath))
// {
// sortPropertyName = binding.XPath;
// }
// else if (binding.Path != null)
// {
// sortPropertyName = binding.Path.Path;
// }
// }
// }
// }
// return sortPropertyName;
//}
public static List<T> AllChildren<T>(this FrameworkElement ele, Func<DependencyObject, bool> whereFunc = null) where T : class
{
if (ele == null)
return null;
var output = new List<T>();
var c = VisualTreeHelper.GetChildrenCount(ele);
for (var i = 0; i < c; i++)
{
var ch = VisualTreeHelper.GetChild(ele, i);
if (whereFunc != null)
{
if (!whereFunc(ch))
{
continue;
}
}
if ((ch is T))
output.Add(ch as T);
if (!(ch is FrameworkElement))
continue;
output.AddRange((ch as FrameworkElement).AllChildren<T>(whereFunc));
}
return output;
}
public static SortDescription? FindSortDescription(SortDescriptionCollection sortDescriptions, string sortPropertyName)
{
foreach (SortDescription sortDesc in sortDescriptions)
if (string.Compare(sortDesc.PropertyName, sortPropertyName) == 0)
return sortDesc;
return null;
}
}
}