デフォルト設定の Uniform の WPF ウィンドウに画像がありStretch
、画面を水平方向に埋めようとしています。Stretch
これは学習経験を想定しているため、別の設定を使用したくありません。読み込まれている画像のサイズは420x800
です。これは、ウィンドウの XAML です。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Red" Height="1200" Width="840">
<Image Name="Image" Source="{Binding SourceUri}">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="Scale" />
<TranslateTransform x:Name="Translate" />
</TransformGroup>
</Image.RenderTransform>
</Image>
</Window>
コードビハインドでは、スケーリングを計算して画像をズームして水平画面全体に表示しようとしていますが、変換変換を使用して画面の中央に移動しています。次のコードは明らかに間違っています...
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WpfApplication1 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
DataContext = this;
double ImageWidth = 420;
Scale.ScaleX = Width / ImageWidth;
Translate.X = -(ImageWidth / 2);
}
public string SourceUri {
get {
return @"C:\Users\Roel\Desktop\test.png";
}
}
}
}
ストレッチと変換がどのように連携しているかを理解しようとしていますが、これに問題があります。変換がどのように適用されるかを明確かつ簡潔に説明する情報源を見つけるのに苦労しているため、詳細な説明への参照であっても、すべての洞察をいただければ幸いです。