secretformula
secretformula

Reputation: 6432

Using WPF Templates

I have a project in which I load data from a file and need to convert the data into a treeviewitem with multiple subitems.

I know that I could programatically added these sub items to a root node using a loop however I feel like there is a most likely a way to use a WPF template and then set the values using that rather than creating and adding many different objects in my code.

Upvotes: 0

Views: 152

Answers (2)

Josh
Josh

Reputation: 2975

To avoid creating the TreeView in code-behind, you would need to bind to a ItemsSource through a HierarchicalDataTemplate.

There are two kinds of data providers built into XAML. The first is an ObjectDataProvider which is something like an ObservableCollection. The second is an XmlDataProvider.

If your file format is XML you can take advantage of the XmlDataProvider and not have to parse your file. If not, you would need to parse your file into something like an ObservableCollection and then use that as the HierarchicalDataTemplate ItemsSource.

Upvotes: 2

Martin Moser
Martin Moser

Reputation: 6269

Sounds like that you are looking for the HierachicalDataTemplates:

http://msdn.microsoft.com/en-us/library/system.windows.hierarchicaldatatemplate.aspx

Upvotes: 0

Related Questions