Canvas is a container control that is used to locate
1. Basic applications
You can compare a canvas to a coordinate system , and all the elements determine their position in the coordinate system by setting the coordinates . The origin of this coordinate system is not in the center , but in its upper-left corner . See
There are four ways to set the coordinates of an element:
Canvas.Top set the distance of elements from the top of the canvas
Canvas.bottom set the distance of elements from the bottom of the canvas
Canvas.Left set the distance of the element from the left edge of the canvas
Canvas.right set the distance of elements from the right edge of the canvas
[HTML]View PlainCopy
<BorderHorizontalAlignment= "Left"VerticalAlignment= "Top"BorderBrush= "Black"borderthickness= "2"> <CanvasBackground= "LightBlue"Width= "The "Height= "The "> <ButtonCanvas.Top= " the">canvas.top= "50"</Button> <ButtonCanvas.bottom= " the">Canvas.bottom= "50"</Button> <ButtonCanvas.Left= " the">canvas.left= "50"</Button> <ButtonCanvas.right= " the">Canvas.right= "50"</Button> </Canvas> </Border>
2. When both left and right,top and bottom are set, whichever is left and top
[HTML]View PlainCopy
< Canvas > < canvas.left= " canvas.top"= " Width= " Height = " the" >button</button> </Canvas >
In contrast, the position of the button is shifted to the right. It seems that Canvas.Top and Canvas.Left have worked, and we can tell that the top left corner coordinates are (20,20)
Of course, you can also get more information from the above code:
The coordinates of the lower left corner of the button (20,40)
The coordinates of the top right corner of the button (70,20)
The coordinates of the lower-right corner of the button (70,40)
How do I get this information? The following slowly explains:
The X-value of the lower-left coordinate of the button is the same as the upper-left corner, also 20. Its y-axis coordinates are added on top of the original: the height of the button is added. So it came out (20,40). The following two coordinates can be launched accordingly.
In the case where both the canvas.left and canvas.right properties are set , only the Canvas.Left attribute works, and canvas.right fails, in effect Canvas.Top and canvas.bottom exist at the same time, just canvas.top a function.
3. Overlap Depth setting
[HTML]View PlainCopy
<Canvas> <RectangleCanvas.ZIndex= "3"Width= "+"Height= "+"Canvas.Top= "+"Canvas.Left= "+"Fill= "Blue"/> <RectangleCanvas.ZIndex= "1"Width= "+"Height= "+"Canvas.Top= "Max"Canvas.Left= "Max"Fill= "Yellow"/> <RectangleCanvas.ZIndex= "2"Width= "+"Height= "+"Canvas.Top= "$"Canvas.Left= "$"Fill= "Green"/> <!--Reverse The order to illustrate Z-index property - <RectangleCanvas.ZIndex= "1"Width= "+"Height= "+"Canvas.Top= "+"Canvas.Left= "$"Fill= "Green"/> <RectangleCanvas.ZIndex= "3"Width= "+"Height= "+"Canvas.Top= " the"Canvas.Left= "Max"Fill= "Yellow"/> <RectangleCanvas.ZIndex= "2"Width= "+"Height= "+"Canvas.Top= "The "Canvas.Left= "+"Fill= "Blue"/> </Canvas>
WPF Road--canvas layout (canvas)