1

我正在为 GBA 游戏制作图形编辑器,并将图像放入 ScrollView。当用户单击 NumericUpDown 时,图像会以放大倍数调整大小。我希望我的 ScrollView 能够适应图像的新大小,以便能够滚动整个图像。我没有使用 MVVM 模式。

这是我的 XAML 的一部分:

<ScrollViewer x:Name="PortraitScrollBar" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" VerticalAlignment="Bottom" HorizontalAlignment="Right">
    <Image x:Name="ImagePortrait" Width="280" Height="280" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" />
</ScrollViewer>

这也是我在 NumericUpDown 的 ValueChanged 事件上调用的函数:

public static void Magnify(ref Image img, WriteableBitmap wBmp, int factor)
{
    img.Source = wBmp.Resize(wBmp.PixelWidth * factor, wBmp.PixelHeight * factor, WriteableBitmapExtensions.Interpolation.NearestNeighbor);  
}

private void PorMagnifyUpDown_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
    if (IsInit)
    {
        Magnify(ref ImagePortrait, currentImage, (int)e.NewValue);
    }
}
4

0 回答 0