Canvas、InkCanvas佈局

一、Canvas

WPF中子元素的絕對定位的佈局控件

  • 其子元素使用WidthHeight定義元素的寬度和高度
  • 使用Convas.LeftConvas.Right)、Convas.TopConvas.Bottom)定義與Convas容器的相對位置
  • 如果同時存在Convas.LeftConvas.RightConvas.TopConvas.Bottom,則Convas.LeftConvas.Top優先生效

例如:

   1: <Canvas>

   2:     <Button Canvas.Left="10" Canvas.Top="10" Height="23" Width="75">LT</Button>

   3:     <Button Canvas.Right="10" Canvas.Top="10" Height="23" Width="75">RT</Button>

   4:     <Button Canvas.Left="10" Canvas.Bottom="10" Height="23" Width="75">LB</Button>

   5:     <Button Canvas.Right="10" Canvas.Bottom="10" Height="23" Width="75">RB</Button>

   6: </Canvas>

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

二、InkCanvas

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

   1: <Window x:Class="WPFLayoutDemo.InkCanvasDemo"

   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

   4:     Title="InkCanvasDemo" Height="200" Width="300">

   5:     <InkCanvas>

   6:         <InkCanvas.DefaultDrawingAttributes>

   7:             <DrawingAttributes Color="Red" />

   8:         </InkCanvas.DefaultDrawingAttributes>

   9:         <Image Width="155" Height="155" InkCanvas.Left="10" InkCanvas.Top="10"

  10:                Source="Logo2.png"/>

  11:     </InkCanvas>

  12: </Window>

InkCanvas

其他的功能與Canvas相近。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章