Template, Itemspanel, Itemcontainerstyle, ItemTemplateCategory: WPF2011-10-12 10:13 4716 People read Comments (0) favorite reports Datagridwpftree
First look at a picture (the image below the net, add a few words)
There is really enough "chaos", slowly to the rationale;
1, template is the style of the accusation pieces
All controls that inherit from the ContentControl class in WPF have this property (inherited from a control such as the TextBlock of the Frameworkelementdl Class). The template is used to define the control structure (Visual Tree), and the style is a little confusing, with each control initially without the style property, and all controls in WPF have a default template. Style is also interpreted, but it only changes the original properties of the control, such as the length and width of the color, and the template can change the shape of the control, and optionally add other controls to enrich the current control. Style can be used to define the styles of all corresponding controls within a range, so it is often used in combination.
[HTML]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- <Style x:key="ListBoxStyle1" targettype="ListBox">
- <Setter property= "Background" value= "#FFFFFFFF"/>
- <Setter property="Template">
- <setter.value>
- <ControlTemplate targettype="ListBox">
- //............ Related code
- </ControlTemplate>
- </setter.value>
- </Setter>
- </Style>
2. Itemspanel is the layout style of the child of the accusation, and only those controls with item have this property, such as the ListBox, Combox,treeview,datagrid,tabelcontrol, and so on.
Eg: When not set, the item subkey of the listbox is arranged vertically, but can be arranged horizontally or in a more complex arrangement by setting the Itempanell.
[HTML]View Plaincopy
- <ListBox >
- <listbox.itemspanel>
- <itemspaneltemplate>
- <virtualizingstackpanel orientation="Horizontal"/>//horizontal arrangement
- </itemspaneltemplate>
- </listbox.itemspanel>
- </ListBox>
3, Itemcontainerstyle is the style of the control subkey, in the ListBox is the ListBoxItem style property, just in the ListBox Itemcontainerstyle indicates that all children of the current control default this style , its format is the style of the corresponding child control.
[HTML]View Plaincopy
- <ListBox itemcontainerstyle="{StaticResource listboxitemstyle}">
- <listboxitem />
- <listboxitem />
- </ListBox>
And
[HTML]View Plaincopy
- <ListBox >
- <listboxitem style="{StaticResource listboxitemstyle}"/>
- <listboxitem style="{StaticResource listboxitemstyle}"/>
- </ListBox>
Equivalence, but obviously the former is much more convenient.
4, ItemTemplate is the style of the control subkey, the same as 1, the usage and 3 inside the same, that is, the child's template property equivalent, but this is obviously more convenient.
Template, Itemspanel, Itemcontainerstyle, ItemTemplate (the item subkey, including the ListBox, is arranged horizontally)