放大画布上的绘图时,我需要显示滚动条。
画布位于 ScrollViewer 中,我增加了画布的宽度/高度,以便出现 scollbars(否则它们不会出现)。
要放大 1.1 倍,我使用以下代码:
Matrix m = this.LayoutTransform.Value;
if (e.Delta > 0) f = 1.1;
else f = 1.0 / 1.1;
m.Scale(f, f);
this.LayoutTransform = new MatrixTransform(m);
this.Height = this.ActualHeight * f;
this.Width = this.ActualWidth * f;
事实证明,画布变得太大了。绘图放大了 10%,但宽度似乎变成了 20%,更像 1.1 的平方。所以我使用Math.Sqrt(f);
而不是f
.
任何人都可以解释为什么它会这样吗?