Answer the question
In order to leave comments, you need to log in
How to implement Hierarchicaldatatemplate in caliburn micro?
Please tell me how to implement Hierarchicaldatatemplate in the TreeView element. I would like to add elements dynamically. The data will be loaded from the database.
In the ViewModel I receive data in this way
public MainViewModel(,ContractService contractService )
{
_contraDataService = contractService;
_contraDataService.GetData(
(items, error) =>
{
contract = items;
});
}
<TreeView>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=contract}">
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TreeViewItem ItemsSource="{Binding Path=product}" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Answer the question
In order to leave comments, you need to log in
You probably forgot to set itemssource for Treeview itself.
After setting all the contracts in the ItemsSource, you will see them, and each will have the products from the product property.
<TreeView>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=product}">
<TextBlock Text="{Binding} />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question