wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了wpf – WinRT中的ClipToBounds属性大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我试图在Windows运行时中找到相当于 ClipToBounds的内容. 如果它不存在有没有办法重新创建这种行为? 这是我使用的解决方案: public class Clip { public static bool GetToBounds(DependencyObject depObj) { return (bool)depObj.GetValue(ToBoun
我试图在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

大佬总结

以上是大佬教程为你收集整理的wpf – WinRT中的ClipToBounds属性全部内容,希望文章能够帮你解决wpf – WinRT中的ClipToBounds属性所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。