TOC

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

Panels:

Introduction to WPF panels

Paneli su jedan od najvažnijih tipova kontrola u WPF-u. Oni služe kao kontejneri za druge kontrole i upravljaju rasporedom prozora i stranica. Pošto prozor može da sadrži samo jednu kontrolu kao dete, panel se često koristi za podelu prostora na različite oblasti, pri čemu svaka oblast može da sadrži kontrolu ili drugi panel (koji je, takođe, kontrola).

Postoje različiti tipovi panela, a svaki tip na svoj način obrađuje layout i child kontrole. Zato je jako bitno izabrati pravi panel, kako bi se dobilo ponašanje i layout koji želite, a ovo je naročito teško na početku WPF karijere. Sledeća sekcija će opisati svaki od panela ukratko i dati vam ideju kada da ga koristite. Nakon toga ćemo se detaljno pozabaviti svakim panelom.

Canvas

Jednostavan panel koji oponaša način rada u WinForms okruženju. Omogućava vam da dodelite određene koordinate svakoj od podređenih kontrola, čime dobijate potpunu kontrolu nad rasporedom. Ovo, međutim, nije fleksibilno jer morate ručno pomerati podređene kontrole i obezbediti njihovo poravnanje prema željenom rasporedu. Koristite ga samo kada vam je potrebna potpuna kontrola nad pozicijama podređenih kontrola.

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

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!
Table of Contents