在调整画布父级大小时,wpf拉伸一条线

Jul*_*ien 3 wpf resize canvas line stretch

我有一个垂直线和一个水平线,当我动态调整画布父级时,我想调整大小.(里程碑)

我希望水平线总是距离画布的左右边界25,距离底部边框13.

垂直线相同,25个远离顶部和底部边界,13个距离左边界.

有简单的解决方案吗?我可以将画布改为另一个控件吗?

Dea*_*alk 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>
Run Code Online (Sandbox Code Playgroud)