调整窗口大小时,保持两个图像相对缩放

时间:2012-09-19 08:05:49

标签: c# wpf

假设有两个图像,一个用于背景,一个用于前景。前景正好位于背景的中间,覆盖了它的相对数量(例如50%),因此用户将它们视为单个图像。

问题在于我需要背景以各种尺寸填充Window。将其Stretch值设置为UniformToFill即可。但是如何保持前景仍然覆盖50%的背景?

1 个答案:

答案 0 :(得分:0)

使用矢量图像会更好,因为它可以在调整容器大小时缩放'本身'

然后根据窗口大小设置边距,如下所示:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Height="400" Width="400">
<Grid>
    <Image Margin="100">
        <Image.Source>
            <DrawingImage>
                <DrawingImage.Drawing>
                    <GeometryDrawing Brush="#FF000000" Geometry="M14.800615,5.6499605L14.800615,14.800346C10.630442,17.910477 7.8903284,22.840685 7.8903284,28.44092 7.9003286,37.871319 15.530646,45.511639 24.961039,45.521641 34.391431,45.511639 42.011749,37.871319 42.04175,28.44092 42.03175,22.840685 39.291636,17.910477 35.121462,14.800346L35.121462,5.6599612C43.841825,9.5601254,49.912077,18.280493,49.912077,28.44092L49.922077,28.44092C49.912077,42.231503 38.741611,53.391972 24.961039,53.391972 11.170465,53.391972 0,42.231503 0,28.44092 0,18.270493 6.0902529,9.5501251 14.800615,5.6499605z M19.570043,0L30.237043,0 30.237043,33.917 19.570043,33.917z" />
                </DrawingImage.Drawing>
            </DrawingImage>
        </Image.Source>
    </Image>
</Grid>

要始终使用50%的窗口,您可以使用Converter绑定属性。

此外,也许this可以帮助您。