将画布调整为网格大小 [英] Resize Canvas To size of grid

查看:118
本文介绍了将画布调整为网格大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有固定大小的网格.在其中,我使用木箱来绘制具有特定坐标,高度和宽度的形状.

现在我将画布设置为网格的宽度和高度.

你能告诉我如何实现吗?

预先感谢!

问候
Govardhan

Hi,

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!

Regards
Govardhan

推荐答案

如果您想使用xaml创建一个带有画布的网格,则可以这样编写:
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>
  </grid>



如果要通过编程实现相同的目标,则应自动"调整画布的宽度和高度,并拉伸画布的水平和垂直对齐方式:



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


这篇关于将画布调整为网格大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆