Silverlight学习笔记基本控件(四)

容器类控件-Canvas:

常用属性有

Canvas.Left

Canvas.Top

Canvas.ZIndex

后台编码设置以上属性语法格式为:

Canvas.SetLeft(Element对象,值)

Canvas.SetTop(Element对象,值)

Canvas.SetZIndex(Element对象,值)

示例代码:

<UserControl x:Class="CanvasDemo.MainPage"
    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"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Canvas >
            <Rectangle RadiusX="25" RadiusY="5" Width="100" Height="100" Stroke="Red" Fill="Red" StrokeThickness="1" ToolTipService.ToolTip="红色长方形=宽:100 高:100  圆角X轴半径:25  圆角Y轴半径:5" Canvas.Left="100" Canvas.Top="30" Canvas.ZIndex="3"></Rectangle>
            <Rectangle RadiusX="25" RadiusY="5" Width="100" Height="100" Stroke="Black" Fill="Black" StrokeThickness="2" ToolTipService.ToolTip="红色长方形=宽:100 高:100  圆角X轴半径:25  圆角Y轴半径:5" Canvas.Left="110" Canvas.Top="60" Canvas.ZIndex="3"></Rectangle>
            <Rectangle RadiusX="25" RadiusY="5" Width="100" Height="100" Stroke="Blue"  Fill="Blue" StrokeThickness="1" ToolTipService.ToolTip="红色长方形=宽:100 高:100  圆角X轴半径:25  圆角Y轴半径:5" Canvas.Left="120" Canvas.Top="90" Canvas.ZIndex="1"></Rectangle>
        </Canvas>
    </Grid>
</UserControl>

你可能感兴趣的:(silverlight)