TOC

This article is currently in the process of being translated into Dutch (~48% done).

Panelen:

Inleiding tot WPF-panelen

Panels zijn één van de belangrijkste control types van WPF. Ze handelen als containers voor andere controls, en controleren de layout van jou vensters/pagina's. Omdat een venster maar één child control kan hebben, wordt een panel vaak gebruikt om de ruimte in verschillende ruimtes op te delen. Elke ruimte kan dan een control of een ander panel bevatten (die natuurlijk ook een control is).

Panels komen in verschillende smaken, elke heeft zijn eigen manier om met layout en child controls om te gaan. Het juiste panel kiezen is daarom essentieel om het gedrag en layout te krijgen die je wilt. Zeker in het begin van jou WPF carriére kan dit een moeilijke taak zijn. De volgende sectie zal elk van de panels kort beschrijven en je een idee geven wanneer je die moet gebruiken. Daarna, ga naar de volgende hoofdstukken, waar elke panel meer in detail zal beschreven zijn.

Canvas

Een simpel paneel, welke op dezelfde manier werkt als de WinForms methode. Het maakt het mogelijk om specifieke coördinaten in te geven voor iedere van de onderliggende onderdelen en biedt dus totale controle over de lay-out van deze onderdelen. Het is echter niet erg flexibel, aangezien je de onderliggende onderdelen handmatig moet positioneren, om zeker te zijn dat ze op de gewenste manier uitgelijnd worden. Het is (alleen) bedoeld om gebruikt te worden als je de volledige controle wilt behouden over de positie van de onderliggende onderdelen.

WrapPanel

Het WrapPanel positioneert elk van zijn kinderen naast elkaar, horizontaal (default) of verticaal, totdat er geen ruimte meer is, dan wordt er doorgeschoven naar de volgende regel en verder gegaan. Gebruik dit paneel wanneer je een verticale of horizontale lijst van elementen wenst die automatisch wrappen wanneer er geen ruimte meer is.

StackPanel

The StackPanel acts much like the WrapPanel, but instead of wrapping if the child controls take up too much room, it simply expands itself, if possible. Just like with the WrapPanel, the orientation can be either horizontal or vertical, but instead of adjusting the width or height of the child controls based on the largest item, each item is stretched to take up the full width or height. Use the StackPanel when you want a list of controls that takes up all the available room, without wrapping.

DockPanel

The DockPanel allows you to dock the child controls to the top, bottom, left or right. By default, the last control, if not given a specific dock position, will fill the remaining space. You can achieve the same with the Grid panel, but for the simpler situations, the DockPanel will be easier to use. Use the DockPanel whenever you need to dock one or several controls to one of the sides, like for dividing up the window into specific areas.

Grid

The Grid is probably the most complex of the panel types. A Grid can contain multiple rows and columns. You define a height for each of the rows and a width for each of the columns, in either an absolute amount of pixels, in a percentage of the available space or as auto, where the row or column will automatically adjust its size depending on the content. Use the Grid when the other panels doesn't do the job, e.g. when you need multiple columns and often in combination with the other panels.

UniformGrid

The UniformGrid is just like the Grid, with the possibility of multiple rows and columns, but with one important difference: All rows and columns will have the same size! Use this when you need the Grid behavior without the need to specify different sizes for the rows and columns.


This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!