-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtensions.cs
More file actions
50 lines (43 loc) · 1.33 KB
/
Copy pathExtensions.cs
File metadata and controls
50 lines (43 loc) · 1.33 KB
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
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
namespace ShortDev.NodeFlow.WinUI;
internal static class Extensions
{
extension(DependencyObject @this)
{
public T FindAscendant<T>()
{
return VisualTreeHelper.GetParent(@this) switch
{
T t => t,
DependencyObject parent => parent.FindAscendant<T>(),
_ => throw new InvalidOperationException($"No ascendant of type {typeof(T).Name} found.")
};
}
}
extension(FrameworkElement @this)
{
/// <summary>
/// https://stackoverflow.com/a/24120993/15213858
/// </summary>
/// <param name="this"></param>
public void BringToFront()
{
if (@this.Parent is not Panel parent)
return;
int currentIndex = Canvas.GetZIndex(@this);
int maxZ = 0;
foreach (var child in parent.Children)
{
if (child == @this)
continue;
var zIndex = Canvas.GetZIndex(child);
maxZ = Math.Max(maxZ, zIndex);
if (zIndex >= currentIndex)
Canvas.SetZIndex(child, zIndex - 1);
}
Canvas.SetZIndex(@this, maxZ);
}
}
}