2016-08-05 27 views
-1

この種の問題を解決できる人はいますか?私は背景イメージを持っており、解像度を変更するとそのイメージの同じ場所にコンポーネントが必要ですが、コンポーネントはビューに応じて同じポイントに留まりますが、イメージには依存しません。私には敏感さの問題がある。画像の絶対位置

例の写真があります。「文章」の点を見てください。

enter image description here

enter image description here

とXAMLコードがあります:

<ScrollViewer VerticalScrollBarVisibility="Auto"> 
     <Grid > 
      <Image Source="Path" Stretch="Fill"/> 
      <Canvas> 

       <Ellipse Fill="White" Height="15" Width="15" Canvas.Left="170" Canvas.Top="103" /> 
       <TextBlock Text="Sentence" Foreground="Green" 
          Width="150" Height="Auto" Canvas.Left="28" Canvas.Top="122" 
          TextWrapping="WrapWholeWords" TextAlignment="Right"/> 
      </Canvas> 
     </Grid> 
</ScrollViewer> 
+1

あなたの質問が何であるかを直接明記する必要がありますので、誰も推測する必要はありません – tCoe

+0

画像に「Stretch = "None"」と設定されている可能性があります。 – Clemens

答えて

1

私はあなたのために、背後にあるコード内の位置を計算し、Canvas.LeftCanvas.Topプロパティをリセットする必要があるだろうと思いは、例:

<ScrollViewer VerticalScrollBarVisibility="Auto"> 
    <Grid> 
     <Canvas x:Name="canvas" SizeChanged="canvas_SizeChanged"> 
      <Canvas.Background> 
       <ImageBrush ImageSource="Assets/111.png" /> 
      </Canvas.Background> 
      <Ellipse x:Name="elps" Fill="White" Height="15" Width="15" Canvas.Left="170" Canvas.Top="103" /> 
      <TextBlock x:Name="tb" Text="Sentence" Foreground="Green" 
        Width="150" Height="Auto" Canvas.Left="28" Canvas.Top="122" 
        TextWrapping="WrapWholeWords" TextAlignment="Right" /> 
     </Canvas> 
    </Grid> 
</ScrollViewer> 
背後

コード:

private double width; 
private double height; 

private void canvas_SizeChanged(object sender, SizeChangedEventArgs e) 
{ 
    if (width == 0 || height == 0) 
    { 
     width = canvas.ActualWidth; 
     height = canvas.ActualHeight; 
    } 
    else 
    { 
     var newwidth = canvas.ActualWidth; 
     var newheight = canvas.ActualHeight; 
     elps.Width = 15 * (newwidth/width); 
     elps.Height = 15 * (newheight/height); 
     Canvas.SetTop(elps, 103 * (newheight/height)); 
     Canvas.SetLeft(elps, 170 * (newwidth/width)); 
     Canvas.SetTop(tb, 122 * (newheight/height)); 
     Canvas.SetLeft(tb, 28 * (newwidth/width)); 
    } 
} 

私は個人的には一つの制御であなたのEllipseTextBlockを入れて一緒に移動する方が良いと思うし、この計算は単なるサンプルです、あなたは自分でそれを計算することができます。

+0

ありがとう。私はそれがviewBoxを使用する方が良いことが分かった。 – LOOK