Bounds.Intersect for WPF

送分小仙女□ 提交于 2019-12-04 18:40:52

So thanks to the comments I was able to do what I needed.

The WPF code now looks like this for all those playing at home:

    public void Compare()
    {

        foreach (List<Label> labels in LabelsList)
        {
            Rect position1 = new Rect();
            position1.Location = labels[1].PointToScreen(new Point(0, 0));                
            position1.Height = labels[1].ActualHeight;
            position1.Width = labels[1].ActualWidth;

            Rect position2 = new Rect();
            position2.Location = labels[0].PointToScreen(new Point(0, 0));
            position2.Height = labels[0].ActualHeight;
            position2.Width = labels[0].ActualWidth;

            if (position1.IntersectsWith(position2))
            {
                labels[1].Foreground = new SolidColorBrush(Colors.Green);
                continue;
            }

            labels[1].Foreground = new SolidColorBrush(Colors.Red);
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!