簡體   English   中英

WPF的Bounds.Intersect

[英]Bounds.Intersect for WPF

我有一個Winforms應用程序,允許用戶在屏幕上拖放一些標簽。

目的是使匹配的標簽彼此重疊。

我在列表中保留了對這些標簽的引用,目前正在通過執行以下操作來檢查它們是否重疊。

    foreach (List<Label> labels in LabelsList)
        {
            var border = labels[1].Bounds;
            border.Offset(pnl_content.Location);

            if (border.IntersectsWith(labels[0].Bounds))
            {
                labels[1].ForeColor = Color.Green;
            }
            else
            {
                labels[1].ForeColor = Color.Red;
            }
        }

問題在於這僅對Winforms(Bounds.Intersect)有好處。 我可以在WPF中做什么以達到相同的結果?

如果有什么不同,我目前正在將兩個標簽添加到視圖中的不同<ItemsControl>中。

因此,由於有了這些評論,我得以完成我需要的工作。

對於所有在家玩的人,WPF代碼現在看起來像這樣:

    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);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM