WPF布局管理之Canvas、InkCanvas (轉)


一、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>
  <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>

在調整窗體大小時,LT與左、上距離保持不變;RT與右、上距離保持不變;LB與左、下距離保持不變;RB與右、下距離保持不變。使用Canvas不能簡單地實現Windows應用程序中Acho的功能。

二、InkCanvas

在WPF中實現允許使用墨跡的控件。如:

 <Window x:Class="WPFLayoutDemo.InkCanvasDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="InkCanvasDemo" Height="200" Width="300">
 <InkCanvas>
     <InkCanvas.DefaultDrawingAttributes>
            <DrawingAttributes Color="Red" />
        </InkCanvas.DefaultDrawingAttributes>

    </InkCanvas>
 </Window>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM