WPF TreeView Hierarchicaldatatemplate

Source: Internet
Author: User

Original WPF TreeView Hierarchicaldatatemplate

 
<StackPanelMargin= "0,0,0,0">            <stackpanel.resources>                <hierarchicaldatatemplatex:key= "Montemp"DataType= "{x:type Local:monthviewmodel}"ItemsSource= "{Binding Fileinfoviewmodels}">                    <TextBlockText="{Binding Monthdescription}"/>                    <hierarchicaldatatemplate.itemtemplate>                        <DataTemplateDataType="{x:type Local:fileinfoviewmodel}">                            <TextBlockText="{Binding FileName}"/>                        </DataTemplate>                    </hierarchicaldatatemplate.itemtemplate>                </hierarchicaldatatemplate>                <hierarchicaldatatemplatex:key= "Yeartemp"DataType= "{x:type Local:yearviewmodel}"ItemsSource= "{Binding Monthviewmodels}"ItemTemplate="{StaticResource Montemp}">                    <TextBlockText="{Binding Yeardescription}"/>                </hierarchicaldatatemplate>            </stackpanel.resources>            <TreeViewHeight= "+"Name= "Filetree">                <treeview.resources>                    <StyleTargetType="{x:type TreeViewItem}">                        <Setter Property= "isexpanded"Value= "True"/>                    </Style>                </treeview.resources>                <TreeViewItemItemsSource="{Binding Treeviewmodels}"Header= "Back Up View"ItemTemplate="{StaticResource Yeartemp}"/>            </TreeView>        </StackPanel>


The datatype of hierarchicaldatatemplate is the binding of this layer, and ItemsSource is a set of objects bound to the layer, it can only use two layers collection, such as Montemp, if you want to use more than three layers, Need two hierarchicaldatatemplate, use ItemTemplate to refer to the other one.

Hierarchicaldatatemplate binding, the child nodes are directly bound DataSource object, not TreeViewItem, so to all default expansion, you want to set style with Treeview.resources.

WPF TreeView Hierarchicaldatatemplate

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.