用 Image.Clip 确定的部分图像区域完全填充 ViewBox

Fill ViewBox completely with part of image area determined by Image.Clip

我有一张大图片想在 Windows Phone 8.1 应用程序中使用。出于我的应用程序的目的,我只想显示图像的特定部分,并希望用该特定部分填充整个 ViewBox。

我可以使用Image.Clip轻松获取图像的特定部分。但是直到现在我还无法让 ViewBox 只填充由 Image.Clip 确定的部分。 我使用以下 XAML.

     <Pivot>
        <PivotItem Margin="10">
            <Viewbox Stretch="Uniform" StretchDirection="Both">
                <Image Source="http://image.png"
                       Stretch="None">
                    <Image.Clip>
                         <RectangleGeometry Rect="500,100,600,700"/>
                    </Image.Clip>
                </Image>
            </Viewbox>
        </PivotItem>
    </Pivot> 

我已经在 Image 和 ViewBox 上尝试了各种 Stretch 设置组合。我也尝试过 ScaleTransforms,但直到现在都没有运气。

所以我的问题是我想在 XAML 中做些什么,如果是的话,我应该使用哪种 XAML 代码组合?

您可以像这样用翻译后的 ImageBrush 填充固定大小的矩形:

<Viewbox Stretch="Uniform" StretchDirection="Both">
    <Rectangle Width="600" Height="700">
        <Rectangle.Fill>
            <ImageBrush ImageSource="http://image.png"
                        Stretch="None" AlignmentX="Left" AlignmentY="Top">
                <ImageBrush.Transform>
                    <TranslateTransform X="-500" Y="-100"/>
                </ImageBrush.Transform>
            </ImageBrush>
        </Rectangle.Fill>
    </Rectangle>
</Viewbox>