如何缩放用户控件背景的 imageBrush?

How to scale the imageBrush of the background of an user control?

我有一个用户控件,我想在其中添加图像作为背景。我正在使用此代码:

<UserControl.Background>
    <ImageBrush ImageSource="x:\myLogo.png"/>
</UserControl.Background>

问题是我找不到缩放图像的方法,因为它填充了用户控件并且不保持比例。我找不到任何方法来缩放和设置图像的其他属性,除了不透明度。

那么,如何缩放和设置图像的填充选项?

谢谢。

ImageBrush has the Stretch property to define how to fit the content using the Stretch enumeration:

Describes how content is resized to fill its allocated space

<ImageBrush ImageSource="../Image.jpg"/>

<ImageBrush ImageSource="../Image.jpg" Stretch="None"/>

<ImageBrush ImageSource="../Image.jpg" Stretch="Uniform"/>

<ImageBrush ImageSource="../Image.jpg" Stretch="UniformToFill"/>

可以使用 Viewbox and Viewport properties like described in this tutorial.

进行进一步的裁剪、整形或缩放调整。