wpf – WinRT中的ClipToBounds属性
发布时间:2020-12-13 20:39:24 所属栏目:Windows 来源:网络整理
导读:我试图在Windows运行时中找到相当于 ClipToBounds的内容. 如果它不存在有没有办法重新创建这种行为? 这是我使用的解决方案: public class Clip{ public static bool GetToBounds(DependencyObject depObj) { return (bool)depObj.GetValue(ToBoundsPropert
我试图在Windows运行时中找到相当于
ClipToBounds的内容.
如果它不存在有没有办法重新创建这种行为?
这是我使用的解决方案:
public class Clip { public static bool GetToBounds(DependencyObject depObj) { return (bool)depObj.GetValue(ToBoundsProperty); } public static void SetToBounds(DependencyObject depObj,bool clipToBounds) { depObj.SetValue(ToBoundsProperty,clipToBounds); } /// <summary> /// Identifies the ToBounds Dependency Property. /// <summary> public static readonly DependencyProperty ToBoundsProperty = DependencyProperty.RegisterAttached("ToBounds",typeof(bool),typeof(Clip),new PropertyMetadata(false,OnToBoundsPropertyChanged)); private static void OnToBoundsPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) { FrameworkElement fe = d as FrameworkElement; if (fe != null) { ClipToBounds(fe); // whenever the element which this property is attached to is loaded // or re-sizes,we need to update its clipping geometry fe.Loaded += new RoutedEventHandler(fe_Loaded); fe.SizeChanged += new SizeChangedEventHandler(fe_SizeChanged); } } /// <summary> /// Creates a rectangular clipping geometry which matches the geometry of the /// passed element /// </summary> private static void ClipToBounds(FrameworkElement fe) { if (GetToBounds(fe)) { fe.Clip = new RectangleGeometry() { Rect = new Rect(0,fe.ActualWidth,fe.ActualHeight) }; } else { fe.Clip = null; } } static void fe_SizeChanged(object sender,SizeChangedEventArgs e) { ClipToBounds(sender as FrameworkElement); } static void fe_Loaded(object sender,RoutedEventArgs e) { ClipToBounds(sender as FrameworkElement); } } 找到它here (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在WIN7下解决coursera视频无法播放问题
- windows – 域中的客户端通知
- windows – 解决托管和本机堆栈跟踪 – 要使用哪个API?
- windows – 在受信任的根证书存储上安装SSL证书的脚本
- windows – TaskKill非常慢
- <Windows> C/C++获取编译时间
- windows-7 – 如何在不使用GUI的情况下为远程桌面授权用户?
- windows-server-2008 – 为什么我不能浏览我的D:驱动器,即
- 如何使用Windows命令行查找文件中字符串的出现次数?
- windows-installer – 我可以在ARPCONTACT属性中显示URL链接