如何以编程方式更改画布的比例?

时间:2015-10-17 10:24:55

标签: c# wpf canvas

给定一个画布对象:

MainCanvas = new Canvas();
MainCanvas.Name = "myCanvas";
MainCanvas.Height = 100;
MainCanvas.Width = 100;

如何通过代码设置其比例(xy)?

1 个答案:

答案 0 :(得分:1)

试试这个:

ScaleTransform scale = new ScaleTransform(MainCanvas.LayoutTransform.Value.M11 * ScaleRate, MainCanvas.LayoutTransform.Value.M22 * ScaleRate);
MainCanvas.LayoutTransform = scale;
MainCanvas.UpdateLayout();