前言
Canvas是一个画布容器,可以通过设置Canvas.Left、Canvas.Top、Canvas.Right、Canvas.Bottom来精确控制子元素在Canvas中的坐标。
1、 Canvas.Left和Canvas.Top
1)Canvas.Left
指定Canvas中子元素距离Canvas左边的距离。
2)Canvas.Top
指定Canvas中子元素距离Canvas上边的距离。
cpp
<Window x:Class="wpf之Canvas.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:wpf之Canvas"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width ="1920">
<Grid>
<Canvas >
<TextBlock Text=" 111" Canvas.Left="10" Canvas.Top="10" Background="Red" Foreground="White" />
<TextBlock Text=" 222" Canvas.Left="100" Canvas.Top="100" Background="Blue" Foreground="White" />
</Canvas >
</Grid>
</Window>
