how WPF layouts work inside
WPF renders layouts with two main tasks: measuring and arranging the measurement phase, the container traversing all the child elements, and inquiring about the desired sizing stages of the child elements, placing the child elements in the appropriate position, and setting the final dimensions of the elements This is a recursive process in which any container element in the interface will be traversed to
inheritance mechanism for WPF layout containers
|
Dispatcherobject
WPF applications use a single-threaded affinity model (Sta:single-thread Affinity), which means that the entire user interface is owned by a single thread, and also means that interacting with user interface elements from another thread is not secure. But there are a lot of situations where interface elements need to be accessed from other threads. WPF has a unified mechanism to deal with these problems, this we in the subsequent chapters involved in the further explanation, as long as you know, as long as the inheritance of Dispatcherobject interface elements can be very convenient to deal with these problems just fine
DependencyObject
The
implementation mechanism of WPF properties differs greatly from the WinForm program, where many of the properties of the WinForm control are inherited through inheritance, and storing a field for each property is a huge waste of memory when you think that the properties of more than 90% UI controls usually leave their initial values. DependencyObject (dependency property) solves the problem of storing only the properties that have changed. The default value is stored only once in the dependency property. This is just one benefit of the dependency property, and there are other benefits we'll talk about later.
Visual
all visual elements in a WPF program are basically inherited from the visual class, which encapsulates drawing instructions and additional drawing details (such as transparency and cropping), and if you do not want to use WPF interface elements, you prefer a lightweight drawing API. Then you can program the visual object directly
UIElement
UIElement adds more functionality to visual elements, such as layout, input, focus, events, commands, etc.
FrameworkElement
Enhancements have been made to UIElement, such as UIElement, which
sets the foundation for the layout mechanism, but FrameworkElement provides important properties that support it, such as HorizontalAlignment, margin, and so
on.
Panel
is the base class for all layout elements, and all layout elements derive from this type, which is used to place and arrange WPF elements that contain only three public properties: Background, Children, Isitemhost ( isitemhost marks the control is not a control like the TreeView, ListView, and so on)
|
Layout Properties
The
child elements within the layout container have a certain discretion over their size and position
.
Child elements can set their own layout properties to adjust their position and size
horizontalalignment |
|
verticalalignment |
|
margin |
|
minwidth/minheight |
|
maxwidth/maxheight |
maximum size |
width/height |
|
Grid row and column dimensions
If you want to explicitly set the grid's row and column dimensions, just set the specific value: <rowdefinition height= "></RowDefinition> However, many times you need to adjust the height or width of the row or column, you can set the auto value for the corresponding property: <rowdefinition height= "Auto" ></RowDefinition> Sometimes you need to proportionally set the height or width of rows and columns, you can use the * wildcard character:
<rowdefinition height= "*" ></RowDefinition> <rowdefinition height= "></" Rowdefinition>
Grid cross-row and cross-column
when you want elements within a Grid to span multiple rows or columns, you can use RowSpan or ColumnSpan to implement <button grid.rowspan= "2" grid.columnspan= "2" ></ Button>
GridSpliter Split window
often there is a need to change the size of the inner area of a window by dragging it Gridspliter can meet this demand very well, reduce the size of other rows or columns while increasing the size of one row or column (because the area of a window is fixed, this is the same size) Note the HorizontalAlignment property must be set
Shared dimensions
Let's say we have two grids, each grid has two rows, and the height of both lines is set to auto, and we want the row height of the two grids to be consistent, which means that the row height of one grid is changed by its own content, and the row height of the other grid changes to the requirements of the previous implementation. It's important to write C # code, and now we can use the Shared Dimensions feature of WPF to do this (as you can see, the button in the second grid doesn't set the height, but it gets taller too)
Balance Table UniformGrid
When you do not want to use the grid complex row and column settings, just want to put the element "average" on the interface, then you can use UniformGrid to achieve such a requirement
Z-Axis Order
we know that in a canvas layout container, if the position overlaps, the elements that are set up will cover the first set elements, and if you want to break this rule, you can use the ZIndex property:
Modify a record
2015-12-26: Writing the first two parts of 2014-12-29: Modify the contents of section II to add the last two sections 2014-12-30: Complete the rest of the content
Resources
"Pro WPF 4.5 in C # 4th Edition" Http://www.cnblogs.com/jimson/archive/2010/07/29/DependencyProperties.html
Learning WPF1.2--WPF Layouts--Understanding layout containers