Get up to 80 % extra points for free! More info:

Lesson 39 - WPF - Container Controls

In the previous lesson, WPF - Menu and Dialog Controls, we continued with our overview of WPF controls and showed how to use application menus and dialogs. Today's and the last tutorial on the basic WPF controls is dedicated to containers.

Containers

Containers are controls that contain other controls. We already know at least the Grid and StackPanel. We use them to align controls in the form according to the rules of the used container type.

Representatives of these containers in WPF are:

  • Canvas
  • DockPanel
  • Grid
  • StackPanel
  • TabControl
  • WrapPanel

Canvas

Canvas is the simplest container. Elements are placed in it using the Left, Top, Right, and Bottom properties, as shown in the following example. The element position is then specified by the distance from these edges. The underlying elements are stacked in the order in which they are defined. We use Canvas mainly for drawing, e.g. some diagrams using geometric shapes or pictures.

Canvas in C# .NET WPF

Example

XAML

<Canvas Background="LightSteelBlue">
    <Button Canvas.Left="10" Canvas.Top="10" Content="Top left"/>
    <Button Canvas.Right="10" Canvas.Top="10" Content="Top right"/>
    <Button Canvas.Left="10" Canvas.Bottom="10" Content="Bottom left"/>
    <Button Canvas.Right="10" Canvas.Bottom="10" Content="Bottom right"/>

    <Rectangle Fill="Lime" Canvas.Left="130"
       Canvas.Top="70" Width="50" Height="50"

 

...End of the preview...
Continue further

You will gain knowledge worth hundreds of thousands for a few crowns

You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.

Buy this course

Buy all currently available lessons with exercise submitting and other features for just $22.50
Current account balance $0
By buying this package, you'll have access to all 42 articles (39 lessons, 3 practical exercises) in this course.

This article is licensed: Premium, by buying this article, you agree with the terms of use.

What will you get from us in the next lessons?
  • Unlimited and permanent access to individual lessons.
  • High quality IT knowledge.
  • Skills to help you get your dream and well-paid job.

Article description

Requested article covers this content:

In this C# .NET WPF tutorial, we'll complete our control overview with containers. These are Canvas, DockPanel, Grid, StackPanel, TabControl, and WrapPanel

You gain credits by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.

Article has been written for you by Petr Pospisil
Avatar
Activities