chenghaoran
2024-02-06 ee0ccdd8306da736205e26c8851c21b2650e3230
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
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
 
namespace WPFProject.Utils
{
    public class CanvasHelper
    {
        public static void SetTopZIndex(object element, DependencyObject parent, Type targetClass)
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
            {
                UIElement child = VisualTreeHelper.GetChild(parent, i) as UIElement;
                if (child != null && targetClass == child.GetType())
                {
                    if (element == child)
                    {
                        Canvas.SetZIndex(child, 1);
                    }
                    else
                    {
                        Canvas.SetZIndex(child, 0);
                    }
                }
 
            }
        }
    }
}