Outside of viewbox
#1
Hi,

Is there a ways to know if a control is in or out of the current viewbox?

I made a test with a grid (inside the zoom panel) that contains 100 x 100 rectangles. I want to change the colors of the rectangles which are inside or outside of the viewbox. In my example the ViewBox.Contains(Point) method never returns true.

public void UpdateViewbox(Ab2d.Controls.ZoomPanel panel)
{
foreach (Rectangle item in MyGrid.Children)
{
Point point = item.TranslatePoint(new Point(0,0), this);
if (panel.Viewbox.Contains(point))
{
item.Fill = Brushes.Red;
}
else
{
item.Fill = Brushes.Blue;
}
}
}

Is there an example of how to do that?
#2
The idea to use TranslatePoint and Contains methods is very interesting.
But the problem is that the ZoomPanel's Viewbox property is in relative units (1 is full width / height), but the translated points are in absolute positions.

The solution is pretty simple - instead of ZoomPanel's Viewbox you need to use a rectangle that is created from ZoomPanel's actual size:

Code:
var zoomPanelBounds = new Rect(0, 0, panel.ActualWidth, panel.ActualHeight);

            foreach (Rectangle item in ItemsGrid.Children.OfType<Rectangle>())
            {
                Point point = item.TranslatePoint(new Point(0, 0), this);
                if (zoomPanelBounds.Contains(point))
                {
                    item.Fill = Brushes.Red;
                }
                else
                {
                    item.Fill = Brushes.Blue;
                }
            }
Andrej Benedik
#3
Thank you for the corrected example, it works perfectly!
  


Forum Jump:


Users browsing this thread:
1 Guest(s)