问题描述
我有一个Canvas,我将Background属性设置为一个由Image组成的VisualBrush。我是将画布的宽度和高度绑定到图像的宽度和高度的数据。这是XAML:
I've got a Canvas that I'm setting the Background property to a VisualBrush consisting of an Image. I'm data binding the Canvas' Width and Height to the Images' Width and Height. Here's the XAML:
<Canvas x:Name="imageCanvas" ClipToBounds="True" Width="{Binding ActualWidth, ElementName=dataImage}" Height="{Binding ActualHeight, ElementName=dataImage}"
Loaded="imageCanvas_Loaded" MouseMove="imageCanvas_MouseMove">
<Canvas.Background>
<VisualBrush Stretch="Uniform">
<VisualBrush.Visual>
<Image x:Name="dataImage" ClipToBounds="True" RenderOptions.BitmapScalingMode="HighQuality" Stretch="Uniform" Source="{Binding DataImage, Mode=OneWay}" LayoutTransform="{Binding DataImageLayoutTransform, Mode=OneWay}"/>
</VisualBrush.Visual>
</VisualBrush>
</Canvas.Background>
</Canvas>
请注意,Image正在使用LayoutTransform。我用它来拉伸图像的宽度。如果我禁用LayoutTransform绑定并运行我得到以下(正确)渲染输出:
Note that Image is using a LayoutTransform. I'm using this to stretch the width of the image. If I disable the LayoutTransform binding and run I get the following (properly) rendered output:
然而,当我添加LayoutTransform以将图像的宽度拉伸6倍时,图像看起来正确拉伸但是它太小了,即它没有统一填充Canvas:
However, when I add the LayoutTransform to stretch the width of the image by a factor of 6, the image looks stretched correctly but it is too small i.e. it is not filling the Canvas uniformly:
我怀疑这可能与将画布高度/宽度绑定到图像高度宽度有关,但目前尚不清楚确切的问题是什么。谁能提供一些见解?提前谢谢。
I suspect this may have something to do with binding the Canvas Height/Width to the image height width, but it's not clear what the exact problem is. Can anyone provide some insight? Thank you in advance.
推荐答案
这篇关于Canvas + VisualBrush不会将图像渲染为均匀填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!