locked
Grid Margin...

    Question

  •  Hey guys, i've a little problem with grid's margin....

    i've tried this simple code : 

     

    <Grid Background="#FFFFFFFF">
            <Grid x:Name="LayoutRoot">
                <Rectangle RadiusX="15" RadiusY="15" Fill="{x:Null}" Stroke="#FF575555" StrokeThickness="1.7"/>
                <Rectangle RadiusX="14" RadiusY="14" Fill="{x:Null}" Stroke="#FFBDF2F2" StrokeThickness="2" Margin="0.688,0.688,0.688,0.688"/>
                <Rectangle RadiusX="14" RadiusY="14" Fill="{x:Null}" Stroke="#FF264D1F" StrokeThickness="1.5" Margin="1.8,1.8,1.8,1.8"/>
                <Rectangle RadiusX="12" RadiusY="12" Stroke="#FF655FCE" StrokeThickness="3.5" Margin="3.457,3.457,3.457,3.457"/>
                <Rectangle RadiusX="12" RadiusY="12" Stroke="#FF57D0D0" StrokeThickness="1.5" Margin="5.1,5.1,5.1,5.1"/>
                <Rectangle RadiusX="11" RadiusY="11" Stroke="#FF0F2D41" StrokeThickness="1.333" Margin="5.6,5.6,5.6,5.6"/>
            </Grid>
        </Grid>

     

    and this is what i've got :

     

     

     

    i don't understand why the grid don't keep the same margin in the bottom, left etc.....

    I've got another question, why I can't move object  with the same precision in the grid that in the canvas... it's seem that in the grid there is step, for example i can only move my object by step of 0.5.... not as precise as i wanted....

    Have a nice day !

     

    Monday, October 27, 2008 10:27 AM

Answers

All replies

  • I believe that the reason it does not look the way you're expecting it to look has to do with the X and Y radius values. I think that if these varied proportionally with the size of each rounded rectangle, then these rectangles would appear to be appropriately centered.  I hope that this helps!

    -Ken

    Monday, October 27, 2008 11:15 AM
  •  hi kwatts, thanks for the answer but even if suppress the radius in X and Y, i've got the same problem...

     

     

     

    it seems that works only with integer......

    Monday, October 27, 2008 11:45 AM
  • I think that you're right about using integers.  Here's what I have after changing the margins to ints:

            <Grid x:Name="LayoutRoot">
                <Rectangle Fill="{x:Null}" Stroke="#FF575555" StrokeThickness="1.7" Margin="10"/>
                <Rectangle Fill="{x:Null}" Stroke="#FFBDF2F2" StrokeThickness="2" Margin="1"/>
                <Rectangle Fill="{x:Null}" Stroke="#FF264D1F" StrokeThickness="1.5" Margin="13"/>
                <Rectangle Stroke="#FF655FCE" StrokeThickness="3.5" Margin="3"/>
                <Rectangle Stroke="#FF57D0D0" StrokeThickness="1.5" Margin="5"/>
                <Rectangle Stroke="#FF0F2D41" StrokeThickness="1.333" Margin="6"/>
            </Grid>

    When I put in fractions, I was having similar problems as what you're experiencing, where things weren't looking perfectly centered.  I'm not sure if there is a general work around for this.

    -Ken

    Monday, October 27, 2008 2:30 PM
  • Is it a kind of bug ?

    Tuesday, October 28, 2008 5:24 AM
  • Is it a kind of bug ?
     

    man it's definetely a bug. I'd say post it to the relative sub-forum

    Sunday, November 9, 2008 5:38 PM
  •  In this post Yi-Lun Luo - MSFT has told for performance benefits, double types are stored as 24 bit float points. I guess this might be the issue for using non integer values.

    Monday, November 10, 2008 4:30 AM
  •  yes but i don't think that the double i was using require more than 24bit and exceed the limit of 24 bit float.

    i've posted a link on the related forum for the bug, i'll see.

    Monday, November 10, 2008 4:41 AM
  •  this might explain.

    Tuesday, November 11, 2008 12:40 PM
  •  yeah with this.LayoutRoot.UseLayoutRounding = false; it works (even if under blend under the design workspace no, in fact yes)

    Wednesday, November 12, 2008 4:26 AM