TOC

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

Panels:

Introduction to WPF panels

A panelek a WPF legfontosabb vezérlő típusai közé tartoznak. A többi vezérlő számára konténerként (összefogó egységként) működnek, ugyanakkor az ablak/oldal elrendezését is vezérlik. Mivel az ablak csak 1 vezérlő elemet tartalmazhat, ezért gyakran használjuk őket a terület felosztására, hogy az így felosztott területen további vezérlőket vagy akár paneleket (ami természetesen szintén egy vezérlő) helyezzünk el.

A paneleknek számtalan különböző formában elérhetőek, és mindegyik a saját módján kezeli az elrendezést és a hozzá rendelt vezérlőket. A megfelelő panel kiválasztása különösen fontos, hogy az általad várt működést és elrendezést érd el. Az elképzelt elrendezés és viselkedés megvalósításához különösen fontos a megfelelő panel típus kiválasztása, mely nehéz feladat lehet, különösen a WPF karriered kezdetén. A következő részben megtalálod a különböző panelek rövid leírását és egy javaslatot, hogy mikor érdemes használnod őket. A következő fejezetek külön-külön foglalkoznak a működés részleteivel.

Canvas

A simple panel, which mimics the WinForms way of doing things. It allows you to assign specific coordinates to each of the child controls, giving you total control of the layout. This is not very flexible though, because you have to manually move the child controls around and make sure that they align the way you want them to. Use it (only) when you want complete control of the child control positions.

WrapPanel

The WrapPanel will position each of its child controls next to the other, horizontally (default) or vertically, until there is no more room, where it will wrap to the next line and then continue. Use it when you want a vertical or horizontal list controls that automatically wraps when there's no more room.

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

A UniformGrid éppen olyan, mint a Grid abban a tekintetben, hogy oszlopokra és sorokra bontható, de egy fontos különbséggel: Minden sor és oszlop ugyanolyan méretű. Akkor érdemes használni, amikor nincs szükség különböző méretű sorokra és oszlopokra.


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!