3

キャンバスの親のサイズを動的に変更するときにサイズを変更したい垂直線と水平線があります。(ランドマーク)

水平線を常にキャンバスの左右の境界線から 25 離し、下の境界線から 13 離したいと思います。

垂直線についても同様で、上下の境界線から 25、左の境界線から 13 離れています。

簡単な解決策はありますか?キャンバスを別のコントロールに変更する必要がありますか?

4

3 に答える 3

7

キャンバス上のグリッドに線を貼り付けるだけで、正しい動作が得られます

<Grid Width="600" Height="600">
   <Canvas Background="LightBlue">
    // stuff here
   </Canvas>
   <Grid>
      <Rectangle Fill="Black" Height="1" 
         Stroke="Black" VerticalAlignment="Bottom" Margin="25,0,25,13"/>
      <Rectangle Fill="Black" 
         HorizontalAlignment="Left" Stroke="Black" Width="1" Margin="13,25,0,25"/>
   </Grid>
</Grid>
于 2012-06-25T15:00:17.153 に答える
3

オブジェクトの高さ、幅、位置を設定するために、あなたのとにConverters基づいて使用しますActualHeightActualWidthCanvasLine

個々のコンバーターをたくさん書くのを避けるために、すべての計算に使用できるMathConverterをブログに投稿しています。

<Canvas x:Name="MyCanvas">

    <!-- Horizontal Line: 25 from each side, and 13 from bottom -->
    <!-- May need to adjust the Canvas.Top ConverterParameter based on Line height -->
    <Line Height="1"
          Canvas.Left="25"
          Canvas.Top="{Binding ElementName=MyCanvas, Path=ActualHeight, 
              Converter={StaticResource MathConverter}, 
              ConverterParameter=@VALUE-14}"
          Width="{Binding ElementName=MyCanvas, Path=ActualWidth, 
              Converter={StaticResource MathConverter}, 
              ConverterParameter=@VALUE-50}" ... />


    <!-- Vertical Line: 25 from top and bottom, and 13 from left -->
    <Line Canvas.Left="13" Canvas.Top="25"
          Height="{Binding ElementName=MyCanvas, Path=ActualHeight, 
              Converter={StaticResource MathConverter}, 
              ConverterParameter=@VALUE-50}" ... />

</Canvas>

これらはすべてバインディングであるため、バインドされたプロパティが変更されるたびに更新されます (MyCanvas.ActualHeightおよびMyCanvas.ActualWidth)

于 2012-06-25T14:24:17.407 に答える
1

を設定する必要がある場合Gridに代わりに使用します。CanvasMargin

行に境界線からのスペースを確保するには、[プロパティ] に移動しMargin、[レイアウト エリア] で使用してスペースを設定します。水平線を に、Horizo​​ntalAlignment を に設定VerticalAlignmentBottomますStretch。この場合の証拠金とします25,0,25,13

垂直線のをにに設定VerticalAlignmentします。マージンはStretchHorizontalAlignmentLeft13,25,0,25

運がいい

于 2012-06-25T14:38:07.890 に答える