Check if frame is in specified position .net maui

Mielesplayz 281 Reputation points
2023-01-24T08:13:42.0133333+00:00

is it possible to check if there is anything in the specified position of a grid?

for example:

if (Frame in Grid.Position(1,7))

{

Console.Write("Specified position is already in use.");

}

I am trying to make a map editor for my own custom game, but frames keep overlapping when you resize it, and I want a way to prevent that from happening.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,413 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,920 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,626 Reputation points Microsoft Vendor
    2023-01-26T12:15:11.34+00:00

    Hello, Your main purpose is to determine if the point will be in the frame, right? If so, you could try to get the left top point of the frame, and calculate the position of the frame, then judge if the (1,7) point is in the position of frame.

    For example:

     public Point GetScreenCoords( VisualElement view)
        {//Get the point in screen, or you can get the Offset in the Parent view according to your needs.
    
            var result = new Point(view.X, view.Y);
            while (view.Parent is VisualElement parent)
            {
                result = result.Offset(parent.X, parent.Y);
                view = parent;
            }
            return result;
        }
    
    private void OnCounterClicked(object sender, EventArgs e)
          {
            var result = GetScreenCoords(MyFrame);
            double a = result.X + MyFrame.Width;
            double b = result.Y + MyFrame.Height;//calculate the range
            if ((result.X<1 && 1 < a) && (result.Y<7 && 7< b))
                {
                      Console.WriteLine("Specified position is already in use.");
                }
        }
    

    Best Regards, Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful