在我对Image控件应用Transform之后,我正在尝试获取它的大小(宽度/高度)(在本例中,不管是呈现还是Layouttransform,都不重要)。
我的Image控件嵌入到ScrollViewer中。我使用Layout/Rendertransform缩放图像,但ActualWidth/ActualHeight或RenderSize属性没有显示新的高度/宽度。我试着在图像控件上调用InvalidateMeasure()和UpdateLayout(),但没有成功。
这是我当前放大图像到高度的代码:
double imageHeight = imageBox.ActualHeight;
double containerHeight = (imageBox.Parent as ScrollViewer).ActualHeight;
double facHeight = containerHeight / imageHeight;
var scaleTransform = imageBox.LayoutTransform.Value; //imageBox.RenderTransform.Value;
scaleTransform.ScalePrepend(facHeight, facHeight);
MatrixTransform newTransform = new MatrixTransform(scaleTransform);
imageBox.LayoutTransform = newTransform;在该方法的第一次执行时,图像将被正确缩放(或多或少)。在本例中,我希望图像垂直完全显示,而不管它的宽度如何,这样我就只能拥有一个水平滚动条(如果imageHeight >imageWidth,则根本没有滚动条)。
在第二次执行时,它会再次放大,因为imageBox.ActualHeight没有改变。
我尝试了InvalidateMeasure和UpdateLayout的各种组合,但这并没有帮助。
发布于 2015-11-23 11:51:56
对于应用LayoutTransform (而不是RenderTransform)后的转换大小,请检查图像控件的DesiredSize属性:
double imageHeight = imageBox.DesiredSize.Height;https://stackoverflow.com/questions/33869137
复制相似问题