Is it possible to display something in my treeview at design time and what would be the best way to achieve it?
Runtime works perfectly well and does display the data I want. However, I would like to have a more convenient display when designing than an empty area where the treeview is.
Thank you.
The treeview looks like this:
<TreeView x:Name="tvConfig" Width="400" Height="300" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type demo:TvItemsSource}" ItemsSource="{Binding Path=Items}">
<StackPanel Orientation="Horizontal">
<Image></Image>
<TextBlock Text="{Binding Name}"></TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
And make uses of this class:
Public Class TvItemsSource
Public Property Items() As New List(Of TvItemsSource)
Public Property Name() As String
Public Sub New(Name As String)
Me.Name = Name
End Sub
End Class
I generated a small runtime data using the following piece of code:
Private _source As TvItemsSource
Private Sub LoadData()
_source = New TvItemsSource("Root")
_source.Items.Add(New TvItemsSource("Item 1"))
_source.Items.Add(New TvItemsSource("Item 2 "))
Dim ParentItem1 = New TvItemsSource("Parent 1")
ParentItem1.Items.Add(New TvItemsSource("Enfant 1"))
Dim ParentItem2 = New TvItemsSource("Parent 2")
ParentItem2.Items.Add(New TvItemsSource("Enfant 2"))
ParentItem1.Items.Add(ParentItem2)
_source.Items.Add(ParentItem1)
tvConfig.ItemsSource = _source.Items
End sub
edit: In the xaml of the treeview, I added the xmlns namespace of the application to declare the data type as :
xmlns:demo="clr-namespace:demo"