私は、画像(上に2行、後で使用するボット)と4つのラジオボタンを含むグリッドを含むグリッドを持っています。画像上に要素を重ねる
ユーザーが画像をクリックすると、クリックしたポイントに十字が表示されます。イベントと
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Image Grid.Row="0"
x:Name="ImageViewer"
Source="{Binding Picture}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
MouseDown="Image_MouseDown"
MouseMove="ImageViewer_MouseMove"
MouseUp="Image_MouseUp"/>
<local:Cross Grid.Row="0"
CenterPoint="{Binding Point1}"
Foreground="Red"/>
<!-- Grid.Row="1" - Grid with RadioButtons -->
</Grid>
:
protected bool StartMove = false;
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
StartMove = true;
Point p = e.GetPosition(ImageViewer);
DrawPoint(p);
}
}
private void Image_MouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
StartMove = false;
}
}
private void ImageViewer_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && StartMove)
{
Point p = e.GetPosition(ImageViewer);
DrawPoint(p);
}
}
画像は(枠なし)完全なサイズである、クロスが正しく描画さ
は、コードの部分があります。私の猫の目をクリックすると、この作られた:
をしかし、私は私の窓のサイズを変更する場合は、クロスが動いています。私は座標が白いスペースを考慮して計算されると思うが、私はこれを防ぐ方法を知らない。
があり、それは同じポイントである:
'Stretch =" None "'を試してみましたが、イメージが非常に小さくなり(デフォルトサイズ)、十字はまだ空白になります。 'Stretch =" Fill "で画像が変形します。少なくとも最良の結果は 'Stretch =" UniformToFill "ですが、Imageの一部がウィンドウから出る –
' Stretch = "Fill" 'は問題を解決するはずです。 'Stretch =" None "'を使うことができます。 'Image'要素自身を自動的にサイズ変更し(ソースイメージのサイズを与えるため)、' Cross'を 'ViewBox'に入れます(スケーリングを自分で処理する)。 – Sinatr