Click here to Skip to main content
15,662,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have grid whose size is fixed. In which i am using casvas to draw shapes with particular coordinates, height and width.

Now i was to set the canvas to the width and height of the grid.

Can you please let me know how it can be achieved.

Thank in advance!


1 solution

If you want to make a grid with a canvas in it using xaml, you can write this :
<grid x:name="grid1" removed="Red" width="300" height="200">
        <canvas x:name="canv1" width="50" height="20" removed="Green"></canvas>

If you want to achieve the same goal programmatically, you should "auto" the width and height of the canvas and stretch the horizontal and vertical alignment of the canvas:
canv1.Width = Double.NaN
        canv1.Height = Double.NaN
        canv1.HorizontalAlignment = Windows.HorizontalAlignment.Stretch
        canv1.VerticalAlignment = Windows.VerticalAlignment.Stretch
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900