Util/FormWPFHelper.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace Util
{
public class FormWPFHelper
{
/// <summary>
/// 获得控件的所在窗口
/// </summary>
/// <param name="ctl"></param>
/// <returns></returns>
public static Window GetControlInWindows(FrameworkElement ctl)
{
FrameworkElement tempCtl = ctl;
while (tempCtl.Parent != null)
{
if (tempCtl.Parent is Window)
return (Window)tempCtl.Parent;
else
tempCtl = (FrameworkElement)tempCtl.Parent;
}
return null;
}
/// <summary>
/// 获得父元素
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public static T GetParentObject<T>(DependencyObject obj) where T : FrameworkElement
{
DependencyObject parent = VisualTreeHelper.GetParent(obj);
while (parent != null)
{
if (parent is T)
{
return (T)parent;
}
parent = VisualTreeHelper.GetParent(parent);
}
return null;
}
/// <summary>
/// 获得指定类型的对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="col"></param>
后面还有 111 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
