Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » Silverlight » Silverlight Canvas Control

Silverlight Canvas Control

A Canvas is one of the Panel elements that enable layout.

Author Rank :
Page Views : 2726
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Defines an area within which you can explicitly position child objects by using coordinates that are relative to the area.
 
Namespace:  System.Windows.Controls

Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)

Public Class Canvas _
    Inherits Panel

Visual Basic (Usage)

Dim instance As Canvas

XAML Object Element Usage

        <Canvas ...>
              oneOrMoreUIElements
        </Canvas>

XAML Values

oneOrMoreUIElements
 
One or more object elements that derive from the UIElement class. Object elements defined here become members of the Children collection.

A Canvas is one of the Panel elements that enable layout. Each child object is rendered within the Canvas area. You control the positioning of objects inside the Canvas by specifying x and y coordinates. These coordinates are in pixels. The x and y coordinates are often specified by using the Canvas..::.Left and Canvas..::.Top attached properties. Canvas..::.Left specifies the object's distance from the left side of the containing Canvas (the x-coordinate), and Canvas..::.Top specifies the object's distance from the top of the containing Canvas (the y-coordinate).

Note: Because absolute positioning does not take into account the size of the browser window or browser resizing, using Grid or StackPanel as a container is often a better choice. For more information, see Silverlight Layout System.

You can nest Canvas objects. When you nest objects, the coordinates used by each object are relative to its immediate containing Canvas.

Each child object must be a UIElement. In XAML, you declare child objects as object elements that are the inner XML of a Canvas object element. In code, you can manipulate the collection of Canvas child objects by getting the collection that is accessed by the Children property.

You can nest Canvas objects, because a Canvas is a type of UIElement.

In many cases, a Canvas is used solely as a container for other objects and does not have any visible properties. A Canvas is not visible if any of the following conditions are true:

  • The Height property is equal to 0.
  • The Width property is equal to 0.
  • The Background property is equal to nullNothingnullptra null reference (Nothing in Visual Basic).
  • The Opacity property is equal to 0.
  • The Visibility property is equal to Visibility..::.Collapsed.
  • One of the ancestor objects of the Canvas is not visible.

Examples

The following example shows how to position a rectangle 30 pixels from the left and 30 pixels from the top of a Canvas.

XAML

        <Canvas Width="640" Height="480" Background="White">
            <Rectangle Canvas.Left="30" Canvas.Top="30"
               Fill="red" Width="200" Height="200" />
        </Canvas>

The preceding example produces output that is similar to the following illustration.

Positioning a rectangle inside the Canvas

canvas1.JPG

In the following example, the root (white) Canvas contains a nested (blue) Canvas that has Canvas..::.Left and Canvas..::.Top properties of 30. The nested blue Canvas contains a red rectangle that also has Canvas..::.Left and Canvas..::.Top values of 30. This creates the effect of a red rectangle bordered by a blue rectangle. This same layout could be achieved using a Border object.
XAML

        <Canvas Width="300" Height="300" Background="White">
            <Canvas Width="250" Height="250" Canvas.Left="30"
            Canvas.Top="30" Background="blue">

                <Rectangle Canvas.Left="30" Canvas.Top="30"
                   Fill="red" Width="200" Height="200" />
            </Canvas>
        </Canvas>

The preceding example produces output that is similar to the following illustration.

Nested objects

canvas2.JPG

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Dinesh Beniwal
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Gauge for SharePoint
Become a Sponsor
 Comments
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.