Alessandro Del Sole's Blog

{ A programming space about Microsoft® .NET® }
posts - 1909, comments - 2047, trackbacks - 352

My Links


Your host

This is me! Questo spazio è dedicato a Microsoft® .NET®, di cui sono molto appassionato :-)

Cookie e Privacy

Microsoft MVP

My MVP Profile

Microsoft Certified Professional

Microsoft Specialist

Xamarin Certified Mobile Developer

Il mio libro su VB 2015!

Pre-ordina il mio libro su VB 2015 Pre-ordina il mio libro "Visual Basic 2015 Unleashed". Clicca sulla copertina per informazioni!

Il mio libro su WPF 4.5.1!

Clicca sulla copertina per informazioni! E' uscito il mio libro "Programmare con WPF 4.5.1". Clicca sulla copertina per informazioni!

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.
If you're not an Italian user, please visit my English blog

Le vostre visite

I'm a VB!

Guarda la mia intervista a Seattle

Follow me on Twitter!

Altri spazi

I miei progetti open-source su GitHub

Article Categories


Post Categories

Image Galleries

Privacy Policy

WPF and the Canvas panel

Until now we've seen a lot of code samples about Windows Presentation Foundation. In these samples we used to place controls particularly inside Grid and StackPanel panels. There is another exciting panel which WPF exposes and that is called Canvas. This panel is really interesting: width and height are always zero but children controls maintain their original size. Morevore, controls can just specify their position inside the container. In this way we have an absolute control positioning and controls maintain their size, just specifying their position in Canvas.

Consider the following XAML:

  <Canvas Background="Orange">
    <Image Canvas.Top="10" Canvas.Left="10" Source="logovbtt.gif" />

It produces the following result to video:

The panel contains an image. This specifies the file to show and Top and Left coordinates of Canvas. So, the image is shown in its original size without specifying any other attribute for dimensioning and stretching. You could try for example to replace the Image element with a Button or with a StackPanel containing two or more Buttons.

Canvas is very useful when you don't want to get crazy about placing and sizing children controls. :-)


Print | posted on lunedì 15 ottobre 2007 23:55 |

Powered by:
Powered By Subtext Powered By ASP.NET