Template, Itemspanel, Itemcontainerstyle, ItemTemplate (the item subkey, including the ListBox, is arranged horizontally)

Source: Internet
Author: User

 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" >
  1. <Style x:key="ListBoxStyle1" targettype="ListBox">
  2. <Setter property= "Background" value= "#FFFFFFFF"/>
  3. <Setter property="Template">
  4. <setter.value>
  5. <ControlTemplate targettype="ListBox">
  6. //............ Related code
  7. </ControlTemplate>
  8. </setter.value>
  9. </Setter>
  10. </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
  1. <ListBox >
  2. <listbox.itemspanel>
  3. <itemspaneltemplate>
  4. <virtualizingstackpanel orientation="Horizontal"/>//horizontal arrangement
  5. </itemspaneltemplate>
  6. </listbox.itemspanel>
  7. </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
    1. <ListBox itemcontainerstyle="{StaticResource listboxitemstyle}">
    2. <listboxitem />
    3. <listboxitem />
    4. </ListBox>

And

[HTML]View Plaincopy
    1. <ListBox >
    2. <listboxitem style="{StaticResource listboxitemstyle}"/>
    3. <listboxitem style="{StaticResource listboxitemstyle}"/>
    4. </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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.