1.Canvas
在WPF中子元素的绝对定位的布局控件
- 其子元素使用Width、Height定义元素的宽度和高度
- 使用Convas.Left(Convas.Right)、Convas.Top(Convas.Bottom)定义与Convas容器的相对位置
- 如果同时存在Convas.Left和Convas.Right、Convas.Top和Convas.Bottom,则Convas.Left、Convas.Top优先生效
如代码:
<Canvas Width="200" Height="200"> <Button Canvas.Left="10" Canvas.Top="10" Height="23" Width="75">LT</Button> <Button Canvas.Right="10" Canvas.Top="10" Height="23" Width="75">RT</Button> <Button Canvas.Left="10" Canvas.Bottom="10" Height="23" Width="75">LB</Button> <Button Canvas.Right="10" Canvas.Bottom="10" Height="23" Width="75">RB</Button>
</Canvas>
设计效果图:矩形区域为Canvas,在调整窗体大小时,LT与左、上距离保持不变;RT与右、上距离保持不变;LB与左、下距离保持不变;RB与右、下距离保持不变。
2.InkCanvas
在WPF中实现允许使用墨迹的控件。
如代码:
<InkCanvas> <InkCanvas.DefaultDrawingAttributes> <DrawingAttributes Color="Red" /> </InkCanvas.DefaultDrawingAttributes> <Image InkCanvas.Left="10" InkCanvas.Top="10" Source="Resources/1.jpg" Margin="0,0,-101,-46"/> </InkCanvas>
效果图:在软件运行后,可在界面上进行标记,其他功能和Canvas类似