Silverlight pixel pixel position?

I am trying to stream a simple game in silverlight (SameGame). The problem is that my old source code was using pixel sizes to evaluate game signs. I am drawing a simple grid using lines and a game mark (using a rectangle). How can I set the lease position correctly? Example 20 20 pixels to the top left corner).

        private void DrawGrid()
    {
        LayoutRoot.Children.Clear();

        Rectangle r = new Rectangle();
        r.Width = 20;
        r.Height = 20;
        r.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
        r.Stroke = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
        r.SetValue(Canvas.LeftProperty, (double)0);
        r.SetValue(Canvas.TopProperty, (double)0);                       
        LayoutRoot.Children.Add(r);


        Color GridColor = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);

        for (int y = 0; y < 11; y++)
        {
            Line l = new Line();
            l.X1 = 0;
            l.Y1 = 30 * y - 1;
            l.X2 = 20 * 30;
            l.Y2 = 30 * y - 1;
            l.Stroke = new SolidColorBrush(GridColor);
            l.StrokeThickness = 1;

            LayoutRoot.Children.Add(l);
        }

        for (int x = 0; x < 21; x++)
        {
            Line l = new Line();
            l.X1 = 30 * x;
            l.Y1 = 0;
            l.X2 = 30 * x;
            l.Y2 = 10 * 30;
            l.Stroke = new SolidColorBrush(GridColor);
            l.StrokeThickness = 1;

            LayoutRoot.Children.Add(l);
        }            
    }

      

+2


source to share


1 answer


You need to place the canvas under the LayoutRoot grid, or change the LayoutRoot to canvas. Then add recangle to Canvas.Children.



0


source







All Articles