移除水印

                FrameworkElement obj = ControlHelper.SearchControls(Application.Current.MainWindow, "__watermark__");
                if (obj != null)
                {
                    (obj as Grid).Children.Clear();
                }


        public static FrameworkElement SearchControls(DependencyObject control,string tagKey)
        {
            FrameworkElement res = null;

            // 遍历当前控件的所有逻辑子控件  
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(control); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(control, i);

                
                if ((child as FrameworkElement).Tag != null)
                {
                    if ((child as FrameworkElement).Tag.ToString().ToLower() == tagKey.ToLower())
                    {
                        res = child as FrameworkElement;
                        break;
                    }
                }

                
                
                res = SearchControls(child, tagKey);
                if (res != null)
                {
                    break;
                }
            }
            return res;
        }

  

posted @ 2024-07-19 14:41  Ender.Lu  阅读(3)  评论(0编辑  收藏  举报