Search This Blog

Monday, November 11, 2013

Canvas WPF Example

WPF > Controls > Layout > Canvas

Canvas is an area within you can set position of child elements by using coordinates that are relative to the Canvas area.
Canvas is the only panel element that has no inherent layout characteristics.
Note: Vertical alignment and horizontal alignment have no effect inside a Canvas.

Example:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Canvas Height="400" Width="400">
        <Canvas Height="153" Width="154" Top="0" Left="0" Background="Red">
            <Ellipse Fill="#FFF4F4F5" Height="56" Stroke="Black" Width="154"/>
            <Rectangle Width="40" Height="50" RenderTransformOrigin="1.9,1.12" Canvas.Left="71" Canvas.Top="26" >
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="Black" Offset="0"/>
                        <GradientStop Color="#FF7C1C1C" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Canvas>
    </Canvas>
</Window>